Strange Perl output

Strange Perl output

am 16.08.2006 13:48:30 von tommy.geerts

Hi ,

I am running this script

#!/usr/local/bin/perl
#
$day =`cat /tmp/currentape | grep "Media Label"`; # Cats the file and
searches it for Monday
if ($day = ~m/ MON /ix){ #if the day contains monday
print "Mondays tape\n $day\n"; #print it is mondays tape
} else {
print "Some other days tape\n"; #if the file does not conatin the label
monday, print some other days tape
}


But the output is :

> ./tapetest.sh
Mondays tape
4294967295


! first issue is its not the moday tape cause when i do the cat
/tmp/currentape | grep "Media Label" the output contains no MON
!! second is that the output of variable $day is in numbers ??

what am i doing wrong.. Thanks !

Strange Perl output--Multiposted

am 16.08.2006 13:53:21 von me

tommy.geerts@gmail.com wrote:
>> [ snip multiposted message ]

This message has been multiposted as indicated by these message IDs:



Multiposting is generally considered impolite in usenet. For an
explanation, please see:

http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

--
msg_hash: 82 - 7b3bbaec622f2431c74f7ce82f50a2f9

Re: Strange Perl output--Multiposted

am 16.08.2006 13:58:35 von tommy.geerts

m...@davidfilmer.net wrote:
> tommy.geerts@gmail.com wrote:
> >> [ snip multiposted message ]
>
> This message has been multiposted as indicated by these message IDs:
>
>
>
> Multiposting is generally considered impolite in usenet. For an
> explanation, please see:
>
> http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
>
> --
> msg_hash: 82 - 7b3bbaec622f2431c74f7ce82f50a2f9

sorryu ,ill remove this one

Re: Strange Perl output

am 16.08.2006 15:55:04 von Sherm Pendley

tommy.geerts@gmail.com writes:

> I am running this script
>
> #!/usr/local/bin/perl
> #
> $day =`cat /tmp/currentape | grep "Media Label"`; # Cats the file and
> searches it for Monday
> if ($day = ~m/ MON /ix){ #if the day contains monday
^^^

You've misplaced a space here. The result is that the = and ~ are taken as
two separate operators, as if you'd written this:

if ($day = ~($_ =~ m/ MON /ix)) { # do stuff...
}

The above takes the return value of the match, performs a bitwise complement
on it, then assigns the result to $day.

What you *meant* to write is this:

if ($day =~ m/ MON /ix) { # do stuff
}

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net

Re: Strange Perl output

am 17.08.2006 16:00:28 von tommy.geerts

Sherm Pendley wrote:
> tommy.geerts@gmail.com writes:
>
> > I am running this script
> >
> > #!/usr/local/bin/perl
> > #
> > $day =`cat /tmp/currentape | grep "Media Label"`; # Cats the file and
> > searches it for Monday
> > if ($day = ~m/ MON /ix){ #if the day contains monday
> ^^^
>
> You've misplaced a space here. The result is that the = and ~ are taken as
> two separate operators, as if you'd written this:
>
> if ($day = ~($_ =~ m/ MON /ix)) { # do stuff...
> }
>
> The above takes the return value of the match, performs a bitwise complement
> on it, then assigns the result to $day.
>
> What you *meant* to write is this:
>
> if ($day =~ m/ MON /ix) { # do stuff
> }
>
> sherm--
>

Thanks sherm !