Strange Perl output
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
tommy.geerts [at] gmail.com wrote:
>> [ snip multiposted message ]
This message has been multiposted as indicated by these message IDs:
<news:1155728910.596976.318600 [at] p79g2000cwp.googlegroups.com>
<news:1155729055.776456.262110 [at] 75g2000cwc.googlegroups.com>
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
m... [at] davidfilmer.net wrote:
> tommy.geerts [at] gmail.com wrote:
> >> [ snip multiposted message ]
>
> This message has been multiposted as indicated by these message IDs:
> <news:1155728910.596976.318600 [at] p79g2000cwp.googlegroups.com>
> <news:1155729055.776456.262110 [at] 75g2000cwc.googlegroups.com>
>
> 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
tommy.geerts [at] 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
Sherm Pendley wrote:
> tommy.geerts [at] 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 !