Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table, 800c5000, setgid operation not permitted, pciehp: acpi_pciehprm on IBM, WWWXXX.DBF, 078274121, info0a ip, should prodicers of software_based services be held liable or not liable for economic injuries

Links

XODOX
Impressum

#1: Strange behaviour in Perl

Posted on 2006-01-25 12:47:17 by Arijit Das

--===============1556606198==
Content-Type: multipart/alternative; boundary="0-2084816457-1138189637=:39791"
Content-Transfer-Encoding: 8bit

--0-2084816457-1138189637=:39791
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

I am just wondering why is this giving a strange result. Any clues...?

bash-2.01$ echo 4.56 | perl -p -e 'my $var1 = <STDIN>; $var2 = $var1 * 100; print $var2;'
04.56
bash-2.01$

I am expecting 456 in the ouput instead of 4.56

Am I missing anything...?

Thanks,
Arijit



---------------------------------
Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo! Mail.
--0-2084816457-1138189637=:39791
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<DIV id=RTEContent>I am just wondering why is this giving a strange result. Any clues...?</DIV> <DIV>&nbsp;</DIV> <DIV>bash-2.01$ echo 4.56 | perl -p -e 'my $var1 = &lt;STDIN&gt;; $var2 = $var1 * 100;&nbsp; print $var2;'<BR>04.56<BR>bash-2.01$</DIV> <DIV>&nbsp;</DIV> <DIV>I am expecting 456 in the ouput instead of 4.56</DIV> <DIV>&nbsp;</DIV> <DIV>Am I missing anything...?</DIV> <DIV>&nbsp;</DIV> <DIV>Thanks,<BR>Arijit</DIV> <DIV>&nbsp;</DIV><p>
<hr size=1>Do you Yahoo!?<br>
With a free 1 GB, there's more in store with <a href="http://us.rd.yahoo.com/mail_us/taglines/mailstorage/*http://mail.yahoo.com/">Yahoo! Mail.</a>
--0-2084816457-1138189637=:39791--

--===============1556606198==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1556606198==--

Report this message

#2: RE: Strange behaviour in Perl

Posted on 2006-01-25 14:04:22 by Joseph.Bautista

This is a multi-part message in MIME format.

--===============0624914272==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0091_01C621C9.02F34BC0"

This is a multi-part message in MIME format.

------=_NextPart_000_0091_01C621C9.02F34BC0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

I think the -p is the one causing the problem



Tried



echo 4.56 | perl -e 'my $var1 = <STDIN> * 100; print $var1;'



and the result is 456







bash-2.01$ echo 4.56 | perl -p -e 'my $var1 = <STDIN>; $var2 = $var1 * 100;
print $var2;'
04.56





I only remove the -p option


--
This message has been scanned for viruses and dangerous content by host-center.net and is believed to be clean.


------=_NextPart_000_0091_01C621C9.02F34BC0
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">=0D

<head>=0D
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Dus-ascii"=
>=0D
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">=0D
<style>=0D
<!--=0D
/* Style Definitions */=0D
p.MsoNormal, li.MsoNormal, div.MsoNormal=0D
{margin:0in;=0D
margin-bottom:.0001pt;=0D
font-size:12.0pt;=0D
font-family:"Times New Roman";}=0D
a:link, span.MsoHyperlink=0D
{color:blue;=0D
text-decoration:underline;}=0D
a:visited, span.MsoHyperlinkFollowed=0D
{color:blue;=0D
text-decoration:underline;}=0D
p=0D
{mso-margin-top-alt:auto;=0D
margin-right:0in;=0D
mso-margin-bottom-alt:auto;=0D
margin-left:0in;=0D
font-size:12.0pt;=0D
font-family:"Times New Roman";}=0D
span.EmailStyle18=0D
{mso-style-type:personal-reply;=0D
color:black;}=0D
@page Section1=0D
{size:8.5in 11.0in;=0D
margin:1.0in 1.25in 1.0in 1.25in;}=0D
div.Section1=0D
{page:Section1;}=0D
-->=0D
</style>=0D

</head>=0D

<body lang=3DEN-US link=3Dblue vlink=3Dblue>=0D

<div class=3DSection1>=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'>I think the &#8211;p is the one caus=
ing=0D
the problem<o:p></o:p></span></font></p>=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'>Tried <o:p></o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'>echo 4.56 | perl -e 'my $var1 =
&lt;STDIN&gt; * 100; print $var1;'<o:p></o:p></span></font></p>=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'>and the result is 456<o:p></o:p></sp=
an></font></p>=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span style=3D=
'font-size:=0D
12.0pt'>&nbsp;<font color=3Dblack><span style=3D'color:black'><o:p></o:p></=
span></font></span></font></p>=0D

<div style=3D'border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in =
4.0pt'>=0D

<div>=0D

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span style=3D=
'font-size:=0D
12.0pt'>bash-2.01$ echo 4.56 | perl -p -e 'my $var1 =3D &lt;STDIN&gt;; $var=
2 =
$var1 * 100;&nbsp; print $var2;'<br>=0D
04.56<font color=3Dblack><span style=3D'color:black'><o:p></o:p></span></fo=
nt></span></font></p>=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'><o:p>&nbsp;</o:p></span></font></p>=
=0D

<p class=3DMsoNormal><font size=3D3 color=3Dblack face=3D"Times New Roman">=
<span=0D
style=3D'font-size:12.0pt;color:black'>I only remove the &#8211;p option<o:=
p></o:p></span></font></p>=0D

</div>=0D

</div>=0D

</div>=0D

</body>=0D


--=20

This message has been scanned for viruses and dangerous content by ho=
st-center.net and is believed to be clean.
</html>=0D

------=_NextPart_000_0091_01C621C9.02F34BC0--



--===============0624914272==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0624914272==--

Report this message

#3: RE: Strange behaviour in Perl

Posted on 2006-01-25 14:20:40 by Chris Newman

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--===============1502795948==
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C621B2.2354419C"

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C621B2.2354419C
Content-Type: text/plain

The -p switch is causing Perl to iterate over the inputs as if they were
filename arguments.



Try this instead...



echo 4.56 | perl -e '$var1 =<STDIN>; $var2 = $var1 * 100; print "$var2\n"'



cn



_____

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of Arijit Das
Sent: Wednesday, January 25, 2006 5:47 AM
To: activeperl@listserv.activestate.com;
perl-unix-users@listserv.activestate.com
Subject: Strange behaviour in Perl



I am just wondering why is this giving a strange result. Any clues...?



bash-2.01$ echo 4.56 | perl -p -e 'my $var1 = <STDIN>; $var2 = $var1 * 100;
print $var2;'
04.56
bash-2.01$



I am expecting 456 in the ouput instead of 4.56



Am I missing anything...?



Thanks,
Arijit



_____

Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo!
<http://us.rd.yahoo.com/mail_us/taglines/mailstorage/*http:/mail.yahoo.com/>
Mail.


------_=_NextPart_001_01C621B2.2354419C
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3DUS-ASCII">


<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
..shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman";}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dblue>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>The &#8211;p switch is causing =
Perl to
iterate over the inputs as if they were filename =
arguments.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Try this =
instead&#8230;<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>echo 4.56 | perl -e '$var1 =
=3D&lt;STDIN&gt;;
$var2 =3D $var1 * 100; print =
&quot;$var2\n&quot;'<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>cn<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<div>

<div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>

<hr size=3D2 width=3D"100%" align=3Dcenter tabindex=3D-1>

</span></font></div>

<p class=3DMsoNormal><b><font size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font =
size=3D2
face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'>
activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] <b><span =
style=3D'font-weight:
bold'>On Behalf Of </span></b>Arijit Das<br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Wednesday, January =
25, 2006
5:47 AM<br>
<b><span style=3D'font-weight:bold'>To:</span></b>
activeperl@listserv.activestate.com; =
perl-unix-users@listserv.activestate.com<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> Strange =
behaviour in Perl</span></font><o:p></o:p></p>

</div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<div id=3DRTEContent>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>I am just wondering why is this giving a strange result. Any =
clues...?<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>bash-2.01$ echo 4.56 | perl -p -e 'my $var1 =3D &lt;STDIN&gt;; =
$var2 =3D
$var1 * 100;&nbsp; print $var2;'<br>
04.56<br>
bash-2.01$<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>I am expecting 456 in the ouput instead of =
4.56<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>Am I missing anything...?<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>Thanks,<br>
Arijit<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font =
size=3D3
face=3D"Times New Roman"><span style=3D'font-size:12.0pt'>

<hr size=3D1 width=3D"100%" align=3Dcenter>

</span></font></div>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'>Do you Yahoo!?<br>
With a free 1 GB, there's more in store with <a
href=3D"http://us.rd.yahoo.com/mail_us/taglines/mailstorage/ *http:/mail.=
yahoo.com/">Yahoo!
Mail.</a><o:p></o:p></span></font></p>

</div>

</body>

</html>

------_=_NextPart_001_01C621B2.2354419C--

--===============1502795948==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1502795948==--

Report this message

#4: Re: Strange behaviour in Perl

Posted on 2006-01-25 14:33:34 by DZ-Jay

Arijit Das wrote:
> I am just wondering why is this giving a strange result. Any clues...?
>
> bash-2.01$ echo 4.56 | perl -p -e 'my $var1 = <STDIN>; $var2 =
$var1 * 100; print $var2;'
> 04.56
> bash-2.01$
>
> I am expecting 456 in the ouput instead of 4.56
>
> Am I missing anything...?
>

Remove -p.

dZ.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#5: Re: Strange behaviour in Perl

Posted on 2006-01-25 14:45:52 by intertwingled

Arijit Das wrote:

>I am just wondering why is this giving a strange result. Any clues...?
>
> bash-2.01$ echo 4.56 | perl -p -e 'my $var1 = <STDIN>; $var2 = $var1 * 100; print $var2;'
>04.56
>bash-2.01$
>
> I am expecting 456 in the ouput instead of 4.56
>
> Am I missing anything...?
>
> Thanks,
>Arijit
>
>
>
>---------------------------------
>Do you Yahoo!?
> With a free 1 GB, there's more in store with Yahoo! Mail.
>
>
>----------------------------------------------------------- -------------
>
>_______________________________________________
>ActivePerl mailing list
>ActivePerl@listserv.ActiveState.com
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
Works fine without the -p.

Tony

--

I always have coffee when I watch radar!

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#6: Re: [Perl-unix-users] Strange behaviour in Perl

Posted on 2006-01-25 15:15:00 by DZ-Jay

Arijit Das wrote:
> I am just wondering why is this giving a strange result. Any clues...?
>

This is from the Perl In A Nutshell book:
------
-p: Causes Perl to assume the following loop around your script, which
makes it iterate over filename arguments:

LINE:
while (<>) {
... # your script goes here
} continue {
print;
}

The lines are printed automatically. To suppress printing, use the -n
switch. If both are specified, the -p switch overrides -n. BEGIN and END
blocks may be used to capture control before or after the implicit loop.
------

So your one-liner is actually:

LINE:
while (<>) {
my $var1 = <STDIN>;
$var2 = $var1 * 100;
print $var2;
} continue {
print;
}

It's already looping through the arguments with while(<>), so reading
<STDIN> will yield nothing. Also, -p implies printing each argument
read, so that's the output that you are getting, not $var2 as you may think.

You have 2 choices, either remove -p to read STDIN as you are doing, or
change -p to -n to supress automatic printing of the input strings and
remove the assignment of STDIN and read $_, which would be the next
argument read from the command line:

echo 4.56 | perl -e 'my $var1=<STDIN>; $var2=$var1*100;print $var2;'

or

echo 4.56 | perl -n -e '$var2=$_*100;print $var2;'

If you keep -p, it'll print the input string right after printing $var2,
like this:

4564.56

Which you do not want.

dZ.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#7: RE: Strange behaviour in Perl

Posted on 2006-01-25 15:25:40 by Brian Raven

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of Arijit
Das
Sent: 25 January 2006 11:47
To: activeperl@listserv.activestate.com;
perl-unix-users@listserv.activestate.com
Subject: Strange behaviour in Perl


> I am just wondering why is this giving a strange result. Any clues...?
>
> bash-2.01$ echo 4.56 | perl -p -e 'my $var1 = <STDIN>; $var2 = $var1 *
100; print $var2;'
> 04.56
> bash-2.01$
>
> I am expecting 456 in the ouput instead of 4.56
>
> Am I missing anything...?

Possibly. Either remove the -p switch, or change your command to echo
4.56 | perl -p -e '$_ *= 100'.

Have you checked 'perldoc perlrun' for what -p does? That may give you a
clue as to what is happening.

HTH

--
Brian Raven



=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of Atos Euronext Market Solutions.

L'information contenue dans cet e-mail est confidentielle et uniquement destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre systeme. Le contenu de ce message electronique ne represente pas necessairement la position ou le point de vue d'Atos Euronext Market Solutions.


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#8: RE: Strange behaviour in Perl

Posted on 2006-01-25 15:25:49 by Bowie Bailey

Arijit Das wrote:
> I am just wondering why is this giving a strange result. Any clues...?
>
> $ echo 4.56 | perl -p -e 'my $var1 = <STDIN>; $var2 = $var1 * 100; print
$var2;'
> 04.56
> $
>
> I am expecting 456 in the ouput instead of 4.56
>
> Am I missing anything...?

The '-p' option is causing the problem. It is adding a loop into the
program. It looks something like this:

while (<>) {

my $var1 = <STDIN>;
$var2 = $var1 * 100;
print $var2;

print $_;
}

So the while loop picks up your input into $_ leaving nothing for you to
read into $var1. Since $var1 is empty, $var2 becomes 0. So you
effectively wind up with this:

print 0;
print 4.56;

which outputs:

04.56

Remove the '-p' and your program will work as expected.

Or use the '-p' and do it like this:

echo 4.56 | perl -p -e '$_ *= 100';

--
Bowie
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#9: Re: [Perl-unix-users] Strange behaviour in Perl

Posted on 2006-01-27 10:02:53 by Arijit Das

--===============0873677828==
Content-Type: multipart/alternative; boundary="0-1263866535-1138352573=:22696"
Content-Transfer-Encoding: 8bit

--0-1263866535-1138352573=:22696
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Thanks a lot folks.

My mistake...I should have looked at "-p"'s significance before posting it.

Thanks again,
Arijit

DZ-Jay <dz@caribe.net> wrote:
Arijit Das wrote:
> I am just wondering why is this giving a strange result. Any clues...?
>

This is from the Perl In A Nutshell book:
------
-p: Causes Perl to assume the following loop around your script, which
makes it iterate over filename arguments:

LINE:
while (<>) {
.... # your script goes here
} continue {
print;
}

The lines are printed automatically. To suppress printing, use the -n
switch. If both are specified, the -p switch overrides -n. BEGIN and END
blocks may be used to capture control before or after the implicit loop.
------

So your one-liner is actually:

LINE:
while (<>) {
my $var1 = ;
$var2 = $var1 * 100;
print $var2;
} continue {
print;
}

It's already looping through the arguments with while(<>), so reading
will yield nothing. Also, -p implies printing each argument
read, so that's the output that you are getting, not $var2 as you may think.

You have 2 choices, either remove -p to read STDIN as you are doing, or
change -p to -n to supress automatic printing of the input strings and
remove the assignment of STDIN and read $_, which would be the next
argument read from the command line:

echo 4.56 | perl -e 'my $var1=; $var2=$var1*100;print $var2;'

or

echo 4.56 | perl -n -e '$var2=$_*100;print $var2;'

If you keep -p, it'll print the input string right after printing $var2,
like this:

4564.56

Which you do not want.

dZ.




---------------------------------

What are the most popular cars? Find out at Yahoo! Autos
--0-1263866535-1138352573=:22696
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<DIV>Thanks a lot folks.</DIV> <DIV>&nbsp;</DIV> <DIV>My mistake...I should have looked at "-p"'s significance before posting it.</DIV> <DIV>&nbsp;</DIV> <DIV>Thanks again,</DIV> <DIV>Arijit<BR><BR><B><I>DZ-Jay &lt;dz@caribe.net&gt;</I></B> wrote:</DIV> <BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Arijit Das wrote:<BR>&gt; I am just wondering why is this giving a strange result. Any clues...?<BR>&gt; <BR><BR>This is from the Perl In A Nutshell book:<BR>------<BR>-p: Causes Perl to assume the following loop around your script, which <BR>makes it iterate over filename arguments:<BR><BR>LINE:<BR>while (&lt;&gt;) {<BR>... # your script goes here<BR>} continue {<BR>print;<BR>}<BR><BR>The lines are printed automatically. To suppress printing, use the -n <BR>switch. If both are specified, the -p switch overrides -n. BEGIN and END <BR
>blocks may be used to capture control before or after the implicit loop.<BR>------<BR><B!
R>So your
one-liner is actually:<BR><BR>LINE:<BR>while (&lt;&gt;) {<BR>my $var1 = <STDIN>;<BR>$var2 = $var1 * 100;<BR>print $var2;<BR>} continue {<BR>print;<BR>}<BR><BR>It's already looping through the arguments with while(&lt;&gt;), so reading <BR><STDIN>will yield nothing. Also, -p implies printing each argument <BR>read, so that's the output that you are getting, not $var2 as you may think.<BR><BR>You have 2 choices, either remove -p to read STDIN as you are doing, or <BR>change -p to -n to supress automatic printing of the input strings and <BR>remove the assignment of STDIN and read $_, which would be the next <BR>argument read from the command line:<BR><BR>echo 4.56 | perl -e 'my $var1=<STDIN>; $var2=$var1*100;print $var2;'<BR><BR>or<BR><BR>echo 4.56 | perl -n -e '$var2=$_*100;print $var2;'<BR><BR>If you keep -p, it'll print the input string right after printing $var2, <BR>like this:<BR><BR
>4564.56<BR><BR>Which you do not want.<BR><BR>dZ.<BR></BLOCKQUOTE> <DIV><BR></DIV><p>
<hr size=1> <BR>
What are the most popular cars? Find out at <a href="http://us.rd.yahoo.com/evt=38382/_ylc=X3oDMTEzNWFva2Y2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDMmF1dG9z/*http://autos.yahoo.com/newcars/popular/thisweek.html
">Yahoo! Autos</a>
--0-1263866535-1138352573=:22696--

--===============0873677828==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0873677828==--

Report this message