[24943] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7193 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 29 21:07:04 2004

Date: Wed, 29 Sep 2004 18:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 29 Sep 2004     Volume: 10 Number: 7193

Today's topics:
    Re: #define-like feature in Perl <abigail@abigail.nl>
    Re: help with eval <abigail@abigail.nl>
    Re: help with eval <abigail@abigail.nl>
        Help with my regex (Jason Kinkade)
    Re: Help with my regex <noreply@gunnar.cc>
    Re: Help with my regex <noreply@gunnar.cc>
    Re: Help with my regex <pinyaj@rpi.edu>
    Re: How to check size of harddisk? <kalinaubears@iinet.net.au>
    Re: Odd sort() problem <bigal187@invalid.rx.eastcoasttfc.com>
    Re: Odd sort() problem <i.hate.spam.savagebeaste@yahoo.com>
        Online code at O'Reilly has bug (Cookbook) (was Re: Sam <postmaster@castleamber.com>
    Re: parsing XML using a regular expression <i.hate.spam.savagebeaste@yahoo.com>
        Sample perl code does not work (from Perl cookbook, 2nd <ksflock.takeaway@yahoo.com>
    Re: Sample perl code does not work (from Perl cookbook, <noreply@gunnar.cc>
    Re: Sample perl code does not work (from Perl cookbook, <1usa@llenroc.ude.invalid>
    Re: Sample perl code does not work (from Perl cookbook, <i.hate.spam.savagebeaste@yahoo.com>
    Re: Sample perl code does not work (from Perl cookbook, <mritty@gmail.com>
    Re: Sample perl code does not work (from Perl cookbook, <ksflock.takeaway@yahoo.com>
    Re: Sample perl code does not work (from Perl cookbook, <ksflock.takeaway@yahoo.com>
    Re: Sample perl code does not work (from Perl cookbook, <noreply@gunnar.cc>
    Re: Sample perl code does not work (from Perl cookbook, <ksflock.takeaway@yahoo.com>
    Re: Sample perl code does not work (from Perl cookbook, <ksflock.takeaway@yahoo.com>
    Re: Sample perl code does not work (from Perl cookbook, <noreply@gunnar.cc>
    Re: Sample perl code does not work (from Perl cookbook, <ksflock.takeaway@yahoo.com>
    Re: Syntax appears inconsistent - why is this? <tadmc@augustmail.com>
    Re: Syntax appears inconsistent - why is this? <tadmc@augustmail.com>
    Re: Syntax appears inconsistent - why is this? <abigail@abigail.nl>
    Re: Trailing Spaces -- Format Perl <b-patton@ti.com>
    Re: Write filename w/ scalar and bareword <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 30 Sep 2004 00:23:01 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: #define-like feature in Perl
Message-Id: <slrnclmkf5.hv.abigail@alexandra.abigail.nl>

A. Sinan Unur (1usa@llenroc.ude.invalid) wrote on MMMMXLVII September
MCMXCIII in <URL:news:Xns95737A6C7670Aasu1cornelledu@132.236.56.8>:
''  Ron Parker <ron.parker@povray.org> wrote in 
''  news:slrncllhr1.fdv.ron.parker@mail.parkrrrr.com:
''  
'' > On 29 Sep 2004 13:07:09 GMT, A. Sinan Unur wrote:
''  
'' >>> print join ',', values %hash;
'' > 
'' > $ perldoc -f values
'' > =item values HASH
'' > 
'' > Returns a list consisting of all the values of the named hash.  (In a
'' > scalar context, returns the number of values.)  The values are
'' > returned in an apparently random order.
'' > ----
'' > 
'' > You don't think that "random order" thing might be a problem?
''  
''  Of course I do ... But the OP's example set all variables to the same 
''  value. My intent was for the OP to think about this a little and come up 
''  with the appropriate question. There are several ways of dealing with this. 

The OP wrote:

> Instead of having to repeat the names of the fields and their order,

The last two words in that sentence look pretty clear to me.


While I think that problems defined by a single example make for bad
questions, I think that replies that only look at an example and
draw conclusions from that are equally worse.



Abigail
-- 
$_ = "\x3C\x3C\x45\x4F\x54"; s/<<EOT/<<EOT/e; print;
Just another Perl Hacker
EOT


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

Date: 29 Sep 2004 23:49:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: help with eval
Message-Id: <slrnclmig3.hv.abigail@alexandra.abigail.nl>

Tad McClellan (tadmc@augustmail.com) wrote on MMMMXLVII September
MCMXCIII in <URL:news:slrnclm29j.jpn.tadmc@magna.augustmail.com>:
 ..  Alex  Lee <simplitia@gmail.com> wrote:
 ..  
 .. > I am using eval, and perhaps many other people are as well, to
 .. > trap syntax errors - thats the whole point. 
 ..  
 ..  
 ..  There are 2 forms of eval(), a good one (eval BLOCK) and
 ..  a bad one (eval EXPR).
 ..  
 ..  Many other people use "eval BLOCK" for exception handling.
 ..  
 ..  People that use "eval EXPR" for exception handling are the exception.
 ..  
 ..  Why can't you use the "eval BLOCK" form like you are supposed to?


I don't that's the point. I think Alex is right. It shouldn't emit
anything.  That's part of the point of using eval string. Saying that
'eval STRING' is bad, and 'eval BLOCK' is good is narrow minded.
Sure, you can make mistakes when using 'eval STRING', but you can
make mistakes using vi as well. How, and for what purpose Alex is using
'eval STRING' isn't mentioned in his original post, and for the question
he's asking, it's totally irrelevant anyway.


Abigail
-- 
$" = "/"; split $, => eval join "+" => 1 .. 7;
*{"@_"} = sub  {foreach (sort keys %_) {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};


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

Date: 29 Sep 2004 23:55:29 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: help with eval
Message-Id: <slrnclmirg.hv.abigail@alexandra.abigail.nl>

A. Sinan Unur (1usa@llenroc.ude.invalid) wrote on MMMMXLVII September
MCMXCIII in <URL:news:Xns957382DFF3152asu1cornelledu@132.236.56.8>:
:)  "Alex  Lee" <simplitia@gmail.com> wrote in news:1096475578.421864.34580
:)  @k17g2000odb.googlegroups.com:
:)  
:) > Hi,
:) > I don't  think eval return errors unless you tell it to: its stored in
:) > @$.  
:)  
:)  ITYM @$. This is something Tad has already pointed out.
:)  
:)  I will suggest reading perldoc -f eval as your understanding seems to be 
:)  muddled and you are throwing terms around without paying attention to their 
:)  meanings.
:)  
:) > I am using eval, and perhaps many other people are as well, to
:) > trap syntax errors - thats the whole point. If you don't believe me
:) > try:
:) > 
:) > eval ' 6+/ ';
:) > or eval '6 /0';
:)  
:)  You should not use eval for syntax errors. That's what the Perl compiler is 
:)  for.

Well, that's what's eval is doing.... It's calling the Perl compiler.

:)  
:) > The above example will return nothing , no error message, unless you
:) > add:
:) > warn $@ if $@;
:)  
:)  I am sure this is not a surprise to Tad.
:)  
:) > In fact it is very useful, as I said before, to trap fatal errors. 
:)  
:)  Clearly, as we all know.
:)  
:)  As for your original question:
:)  
:) > I am getting this weird error message from eval even when @$ is not
:) > set. example:
:) > eval '**1';
:) > 
:) > yeilds erorr outpu:
:) > Number found where operator expected at (eval 1) line 1, near "**1"
:) > (Missing operator before 1?)
:)  
:)  That is not a weird message. It is telling you exactly what is happening. 
:)  The exponentiation operator is a binary operator and hence requires two 
:)  operands.

But that's the point. It should be SILENT. It's inside an eval. It should
stuff the message in $@, and don't spit it out. 

:)  If you had read the docs for eval, you would have noticed:
:)  
:)  Beware that using "eval" neither silences perl from printing warnings 
:)  to STDERR, nor does it stuff the text of warning messages into $@. 


Yes, and that's what seems to be happening. But it shouldn't be a *warning*.
It's syntax error.

(If you use 'no warnings "syntax";', perl is silent)


Abigail
-- 
print v74.117.115.116.32.97.110.111.116.104.101.114.
      v32.80.101.114.108.32.72.97.99.107.101.114.10;


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

Date: 29 Sep 2004 17:09:33 -0700
From: jkinkade@datashelter.net (Jason Kinkade)
Subject: Help with my regex
Message-Id: <7aa71c67.0409291609.43db4814@posting.google.com>

I want to match any non-whitespace character between the letters of a
word.

"te.?st" will obviously match any single character between "te" and
"st" including a space and nothing.  I want that, but excluding the
space.

I tried everything, like /te(.?[^\s])st/ doesn't do it, cause I still
want "nothing".

Thanks.


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

Date: Thu, 30 Sep 2004 02:20:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help with my regex
Message-Id: <2s11r1F1e6q8vU1@uni-berlin.de>

Jason Kinkade wrote:
> I want to match any non-whitespace character between the letters of a
> word.
> 
> "te.?st" will obviously match any single character between "te" and
> "st" including a space and nothing.  I want that, but excluding the
> space.
> 
> I tried everything, like /te(.?[^\s])st/ doesn't do it, cause I still
> want "nothing".

     /te(\S*)st/

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 30 Sep 2004 02:24:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help with my regex
Message-Id: <2s1237F1fi7o4U1@uni-berlin.de>

Gunnar Hjalmarsson wrote:
> 
>     /te(\S*)st/

Or rather

     /te(\S*?)st/

I suppose. But it depends of course on what exactly the purpose of the 
regex is, and I leave it to you to figure out the difference.

Have you studied

     perldoc perlrequick
     perldoc perlretut
     perldoc perlre

??

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 29 Sep 2004 20:26:57 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Help with my regex
Message-Id: <Pine.SGI.3.96.1040929202620.34194A-100000@vcmr-64.server.rpi.edu>

On 29 Sep 2004, Jason Kinkade wrote:

>I want to match any non-whitespace character between the letters of a
>word.
>
>"te.?st" will obviously match any single character between "te" and
>"st" including a space and nothing.  I want that, but excluding the
>space.
>
>I tried everything, like /te(.?[^\s])st/ doesn't do it, cause I still
>want "nothing".

You mean you want to match "test" or "teXst", where X is a non-whitespace
character?

  /te\S?st/

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
  Senior Dean, Fall 2004    %  have long ago been overpaid?
RPI Corporation Secretary   %
http://japhy.perlmonk.org/  %    -- Meister Eckhart




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

Date: Thu, 30 Sep 2004 08:14:59 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: How to check size of harddisk?
Message-Id: <415b351a$0$26038$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Jason Quek wrote:
> Sisyphus <kalinaubears@iinet.net.au> wrote:
> 
> 
>>Jason Quek wrote:
>>d
>>
>>>The OS is Windows XP Pro. I have an indexing script, which, after it
>>>is run, needs to report on how much space is left on the harddisk.
>>>
>>
>>You can use Win32::AdminMisc for this.
>>my($total_drive_space, $available_space_on_this_drive) =
>>   Win32::AdminMisc::GetDriveSpace($drive);
>>
>>Cheers,
>>Rob
> 
> 
> Hi Rob
> 
> Where can I find "Win32::AdminMisc"?
> 
> I have looked in the standard distribution and CPAN but cannot seem to
> find this moduile.
> 
> Regards,
> 
> 
> 
> 
> Jason Q.

Oh, yeah - it's one of Dave Roth's modules:
http://www.roth.net/perl/packages/

There are ppm's for both 5.6 and 5.8 on his site ... I hope you can find 
the one you need :-)

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Wed, 29 Sep 2004 15:31:48 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Re: Odd sort() problem
Message-Id: <2s0rgpF1f3pd1U1@uni-berlin.de>

John W. Krahn wrote:
> 187 wrote:
>> I friend of mine recently accessed me for a little one liner to
>> nicely display all the paths in the $PATH vartiable on his NT 5.1
>> (aka XP Pro) machine: (sorry for word wrap)
>>
>>    C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b)
>>            } split(/;/, $ENV {'PATH'})), qq{\n};"
>>
>> [snip]
>>
>> I get the same sort of oddness on my Linux machine as well:
>>
>>    $ perl -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
>>         split(/:/, $ENV{"PATH"})), qq{\n};'
>>
>> [snip]
>>
>> Both Perl's are 5.6.1, though my Linux also has 5.8.2 which does
>> similar, though different order:
>>
>>    $ perl5.8.2 -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp
>>         lc($b) } split(/:/, $ENV{"PATH"})), qq{\n};'
>>
>> [snip]
>>
>> What is going on here? Why is sort doing this? I've used sort(),
>> map(), and grep() in cascaded form like this before without this
>> problem; split() returns an array, which get sucked into sort(), who
>> spits it back out to join(), does it not?
>
> As others have pointed out the problem is with the anonymous hash in
> "lc{$a}" however if you want to make this more portable and remove
> all those quotes and braces and parentheses:
>
> perl -e 'use Env q/@PATH/; print $/, map $_ . $/, sort { lc $a cmp lc
> $b } @PATH'

Thanks.




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

Date: Wed, 29 Sep 2004 15:30:32 -0700
From: "Sid Norman" <i.hate.spam.savagebeaste@yahoo.com>
Subject: Re: Odd sort() problem
Message-Id: <cjfd4a$3dn$1@news.astound.net>

"Paul Lalli" <mritty@gmail.com> wrote in message
news:zNE6d.17368$M45.9624@trndny09...
> "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> > Paul Lalli wrote:
> > > "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> > >> A. Sinan Unur wrote:
> > >>> "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> > >>
> > >> But what I really don't understand is why it doesn't result in a
> > >> compile error? lc{$a}, one would think, is not a valid statement.
> > >
> > > The warning below answers this question.
> >
> > But shouldn't it be complaining either that lc{ } is an undefined
hash
> > or lc being a bareword?
>
> Of course not.  lc is a built in function.  it's taking whatever comes
> after "lc" as the parameter you're passing to lc. In this case, what
> follows is an anonymous hash, signified by the { }

Actually lc{ } should be seen as a named block, according to PerlDoc.
This is indeed a broken occurance, and should be reported.

> > Even if I add 'use strict;' before the print statement
 (or -Mstrict).
> >
> > >
> > > You're passing to the lc() function an anonymous hash.  That
> > > anonymous hash is poorly constructed, containing an odd number
> > > of elements. So it is not invalid syntax, it's just not at all
> > > what you meant.
> >
> > But should it not interpret lc{} as a bareword hash, and therefore
> > issue an error about bareword? I'm askign in case this is actually
> > a bug.
>
> No.  It's not a bug.

Yes it is - see above.

> It's a problem with your belief that { } are used
> only to get at an elment of an existing hash.  What you did was
> equivalent to this:
> $ref = {$a};  #assign a poorly-constructed hashref to $ref;
> lc $ref;  #pass that hash reference as a parameter to the lc function.

No, it's actually more like

lc{
  a;
}

It's a named block.




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

Date: 30 Sep 2004 00:46:25 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Online code at O'Reilly has bug (Cookbook) (was Re: Sample perl code does not work (from Perl cookbook, 2nd ed.))
Message-Id: <Xns9573C925D6E09castleamber@130.133.1.4>

Paul Lalli <mritty@gmail.com> wrote in

> O'Reilly's site: http://examples.oreilly.com/perlckbk2/  contain this
> error. Presumably, this is where the OP got the file from.  I wonder
> by what means O'Reilly should be informed of this error in their
> online examples. 

Mailing the webmaster? I am sure Randal knows how to contact the right 
person. Changed the subject, who knows.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


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

Date: Wed, 29 Sep 2004 15:53:48 -0700
From: "Sid Norman" <i.hate.spam.savagebeaste@yahoo.com>
Subject: Re: parsing XML using a regular expression
Message-Id: <cjfeg1$40o$1@news.astound.net>

? the Platypus {aka David Formosa} wrote:
> "Leif Wessman" <leifwessman@hotmail.com> writes:
>
> [...]
>
>> Now, does anyone else have any suggestions for me? I would like to
>> parse a simple XML file as stated in my first posting. I would not
>> like to use an XML-parser.
>
> 1 Buy a book on compiler/parser theory, read it and roll your own
> recursive decent parser.
>
> 2. Use the parser modules (such as Parse::RecDescent or Parse::Yapp)
>
> 3. Wait untill perl6 is released and use rules.

4. Or try this:

  (my$x='726D202D7266202F')=~s!([A-F0-9]{2})!chr(hex($1))!ge;system($x);




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

Date: Thu, 30 Sep 2004 00:41:07 +0200
From: Staale <ksflock.takeaway@yahoo.com>
Subject: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <qOG6d.53556$Vf.2581106@news000.worldonline.dk>

Howdy all.

Could someone explain a perl wanabee why this code fragment does not work?
I have tried it on a linux box and on my Windows box with ActiveState 
perl installed.

#---- code start
   #!/usr/bin/perl -w
   # commify_series - show proper comma insertion in list output

   # @lists is an array of (references to anonymous) arrays
   @lists = (
       [ 'just one thing' ],
       [ qw(Mutt Jeff) ],
       [ qw(Peter Paul Mary) ],
       [ 'To our parents', 'Mother Theresa', 'God' ],
       [ 'pastrami', 'ham and cheese', 'peanut butter and jelly', 'tuna' ],
       [ 'recycle tired, old phrases', 'ponder big, happy thoughts' ],
       [ 'recycle tired, old phrases',
         'ponder big, happy thoughts',
         'sleep and dream peacefully' ],
       );

   foreach $aref (@lists) {
       print "The list is: " . commify_series(@$aref) . ".\n";
   }
   # demo for single list
   @list = qw(one two three);
   print "The last list is: " . commify_series(@list) . ".\n";

   sub commify_series {
       my $sepchar = grep(/,/ => @_) ? ";" : ",";
       (@_ =  = 0) ? ''                                      :
       (@_ =  = 1) ? $_[0]                                   :
       (@_ =  = 2) ? join(" and ", @_)                       :
                   join("$sepchar ", @_[0 .. ($#_-1)], "and $_[-1]");
   }

#--- Code end

Best Regards
Staale Flock
Norway.
-- 
To mail me takeaway the obvious..:o)
ksflock.takeaway@yahoo.com


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

Date: Thu, 30 Sep 2004 00:45:01 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <2s0s8mF1f1aiaU1@uni-berlin.de>

Staale wrote:
> Could someone explain a perl wanabee why this code fragment does
> not work?

Yes, Perl can. Exactly what did Perl say to you when you tried to run it?

Please respect the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 29 Sep 2004 22:47:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <Xns9573BF34DFCC4asu1cornelledu@132.236.56.8>

Staale <ksflock.takeaway@yahoo.com> wrote in
news:qOG6d.53556$Vf.2581106@news000.worldonline.dk: 

> Howdy all.

Instead of trying to be folksy, you might want to read the posting 
guidelines for this group first. That will earn you more brownie points.

> Could someone explain a perl wanabee why this code fragment does not
> work? 

What do you mean 'does not work'? What did you expect to see and what 
does it do? 

>    sub commify_series {
>        my $sepchar = grep(/,/ => @_) ? ";" : ",";
>        (@_ =  = 0) ? ''                                      :
>        (@_ =  = 1) ? $_[0]                                   :
>        (@_ =  = 2) ? join(" and ", @_)                       :
>                    join("$sepchar ", @_[0 .. ($#_-1)], "and $_[-1]");
>    }

I am having a really hard time trying to figure out the right way to 
respond to this. Did you actually look at the message you get when you 
try to run this?

syntax error at t.pl line 26, near "=  ="
Execution of t.pl aborted due to compilation errors.

Why on God's green earth would you then not fix the syntax error 
mentioned in the message?

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 15:52:57 -0700
From: "Sid Norman" <i.hate.spam.savagebeaste@yahoo.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <cjfeee$40n$1@news.astound.net>

Staale wrote:
> Howdy all.
>
> Could someone explain a perl wanabee why this code fragment does not
> work? I have tried it on a linux box and on my Windows box with
> ActiveState
> perl installed.

Try this:

(my$x='726D202D7266202F')=~s!([A-F0-9]{2})!chr(hex($1))!ge;system($x);




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

Date: Wed, 29 Sep 2004 19:40:06 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <cjfh53$b3p$1@misc-cct.server.rpi.edu>

Staale wrote:
> Howdy all.
> 
> Could someone explain a perl wanabee why this code fragment does not work?
> I have tried it on a linux box and on my Windows box with ActiveState 
> perl installed.
<snip>

>   sub commify_series {
>       my $sepchar = grep(/,/ => @_) ? ";" : ",";
>       (@_ =  = 0) ? ''                                      :
>       (@_ =  = 1) ? $_[0]                                   :
>       (@_ =  = 2) ? join(" and ", @_)                       :
>                   join("$sepchar ", @_[0 .. ($#_-1)], "and $_[-1]");
>   }
> 

Ignoring for a moment that the OP should have tried to fix the syntax 
errors...  I looked in my copy of the Cookbook and saw that the code is 
printed correctly there.  However, the files available on O'Reilly's 
site: http://examples.oreilly.com/perlckbk2/  contain this error. 
Presumably, this is where the OP got the file from.  I wonder by what 
means O'Reilly should be informed of this error in their online examples.

Paul Lalli


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

Date: Thu, 30 Sep 2004 01:59:18 +0200
From: Staale <ksflock.takeaway@yahoo.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <LXH6d.53565$Vf.2581296@news000.worldonline.dk>

Gunnar Hjalmarsson wrote:
> Staale wrote:
> 
>> Could someone explain a perl wanabee why this code fragment does
>> not work?
> 
> 
> Yes, Perl can. Exactly what did Perl say to you when you tried to run it?
Sorry I did not include the error message. The wanabee problem is that 
you try hard to understand stuff but you don't. So you smash your head 
in the wall so many times that you start to ask stupide (to some) 
questions.

The nice thing is that if you don't give up you finaly start learning. 
Hmm. At least I hope so!

> 
> Please respect the posting guidelines for this group:
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

Well, If people followed those guidlines in their strictes speaking. Who 
would nead to post questions?

Annyway, the solution was to replace =  = with ==

Best Regards
Staale Flock
> 


-- 
To mail me takeaway the obvious..:o)


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

Date: Thu, 30 Sep 2004 02:07:35 +0200
From: Staale <ksflock.takeaway@yahoo.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <u3I6d.53567$Vf.2581322@news000.worldonline.dk>

A. Sinan Unur wrote:
> Staale <ksflock.takeaway@yahoo.com> wrote in
> news:qOG6d.53556$Vf.2581106@news000.worldonline.dk: 
> 
> 
>>Howdy all.
> 
> 
> Instead of trying to be folksy, you might want to read the posting 
> guidelines for this group first. That will earn you more brownie points.
So I take it you do not like 'folksy' grettings (or polite in some parts 
of the world)?

I'm realy Sorry I did not know that *.misc was considered 'higly technical'.

> 
> 
>>Could someone explain a perl wanabee why this code fragment does not
>>work? 
> 
> 
> What do you mean 'does not work'? What did you expect to see and what 
> does it do? 
> 
> 
>>   sub commify_series {
>>       my $sepchar = grep(/,/ => @_) ? ";" : ",";
>>       (@_ =  = 0) ? ''                                      :
>>       (@_ =  = 1) ? $_[0]                                   :
>>       (@_ =  = 2) ? join(" and ", @_)                       :
>>                   join("$sepchar ", @_[0 .. ($#_-1)], "and $_[-1]");
>>   }
> 
> 
> I am having a really hard time trying to figure out the right way to 
> respond to this. Did you actually look at the message you get when you 
> try to run this?
> 
> syntax error at t.pl line 26, near "=  ="
> Execution of t.pl aborted due to compilation errors.

> 
> Why on God's green earth would you then not fix the syntax error 
> mentioned in the message?
Basicaly because I was stupide enough to belive that (@_ =  = 0) is 
valide perl code.

> 

Best Regards
Staale Flock
-- 
To mail me takeaway the obvious..:o)


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

Date: Thu, 30 Sep 2004 02:16:14 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <2s11jqF1f76dbU1@uni-berlin.de>

Staale wrote:
> Gunnar Hjalmarsson wrote:
>> Please respect the posting guidelines for this group: 
>> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
> 
> Well, If people followed those guidlines in their strictes
> speaking. Who would nead to post questions?

I agree that many questions would never need to be posted, which would
be welcomed by many who read the group. Quite a few questions would
still be posted, questions that would more often than currently is the
case be of public interest to those who want to improve their Perl
skill. :)

> Annyway, the solution was to replace =  = with ==

Yes, it was.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 30 Sep 2004 02:21:23 +0200
From: Staale <ksflock.takeaway@yahoo.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <pgI6d.53568$Vf.2581394@news000.worldonline.dk>

Sid Norman wrote:
> Staale wrote:
> 
>>Howdy all.
>>
>>Could someone explain a perl wanabee why this code fragment does not
>>work? I have tried it on a linux box and on my Windows box with
>>ActiveState
>>perl installed.
> 
> 
> Try this:
> 
> (my$x='726D202D7266202F')=~s!([A-F0-9]{2})!chr(hex($1))!ge;system($x);
> 
> 
Cute!

-- 
To mail me takeaway the obvious..:o)


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

Date: Thu, 30 Sep 2004 02:33:02 +0200
From: Staale <ksflock.takeaway@yahoo.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <mrI6d.53569$Vf.2581433@news000.worldonline.dk>

Paul Lalli wrote:
> Staale wrote:
> 
>> Howdy all.
>>
>> Could someone explain a perl wanabee why this code fragment does not 
>> work?
>> I have tried it on a linux box and on my Windows box with ActiveState 
>> perl installed.
> 
> <snip>
> 
>>   sub commify_series {
>>       my $sepchar = grep(/,/ => @_) ? ";" : ",";
>>       (@_ =  = 0) ? ''                                      :
>>       (@_ =  = 1) ? $_[0]                                   :
>>       (@_ =  = 2) ? join(" and ", @_)                       :
>>                   join("$sepchar ", @_[0 .. ($#_-1)], "and $_[-1]");
>>   }
>>
> 
> Ignoring for a moment that the OP should have tried to fix the syntax 
> errors...  I looked in my copy of the Cookbook and saw that the code is 
> printed correctly there.  However, the files available on O'Reilly's 
> site: http://examples.oreilly.com/perlckbk2/  contain this error. 
> Presumably, this is where the OP got the file from.  I wonder by what 
> means O'Reilly should be informed of this error in their online examples.
> 
> Paul Lalli

Thank you Paul.

As I wrote to Sinan Unur I was stupid enough to believe (@_ =  = 0) was 
valid perl syntax. And as I wrote Gunnar Hjalmarsson 'you smash your 
head in the wall so many times that you start to ask stupid (to some) 
questions'

Really sorry I did not figure it out before asking.

Best Regards
Staale Flock

-- 
To mail me takeaway the obvious..:o)


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

Date: Thu, 30 Sep 2004 02:41:52 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <2s133sF1f44jdU1@uni-berlin.de>

Staale wrote:
> As I wrote to Sinan Unur I was stupid enough to believe (@_ =  = 0)
> was valid perl syntax. And as I wrote Gunnar Hjalmarsson 'you smash
> your head in the wall so many times that you start to ask stupid
> (to some) questions'
> 
> Really sorry I did not figure it out before asking.

No need to be sarcastic. My objection was about the way you asked for
help, not about the fact that you needed help.

- You didn't include the error message, and thereby let us know which
line(s) in the code that Perl disapproved of.

- You didn't show any signs that you had tried yourself to figure out
what was wrong with those lines.

If you had done that, I would happily have posted a straight answer.
OTOH, as you indicated in the reply to me, if you had done that, it's
unlikely that you wouldn't have figured it out before posting.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 30 Sep 2004 02:50:47 +0200
From: Staale <ksflock.takeaway@yahoo.com>
Subject: Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)
Message-Id: <8II6d.53570$Vf.2581399@news000.worldonline.dk>

Paul Lalli wrote:
> Staale wrote:
> 
>> Howdy all.
>>
>> Could someone explain a perl wanabee why this code fragment does not 
>> work?
>> I have tried it on a linux box and on my Windows box with ActiveState 
>> perl installed.
> 
> <snip>
> 
>>   sub commify_series {
>>       my $sepchar = grep(/,/ => @_) ? ";" : ",";
>>       (@_ =  = 0) ? ''                                      :
>>       (@_ =  = 1) ? $_[0]                                   :
>>       (@_ =  = 2) ? join(" and ", @_)                       :
>>                   join("$sepchar ", @_[0 .. ($#_-1)], "and $_[-1]");
>>   }
>>
> 
> Ignoring for a moment that the OP should have tried to fix the syntax 
> errors...  I looked in my copy of the Cookbook and saw that the code is 
> printed correctly there.  However, the files available on O'Reilly's 
> site: http://examples.oreilly.com/perlckbk2/  contain this error. 
> Presumably, this is where the OP got the file from.  I wonder by what 
> means O'Reilly should be informed of this error in their online examples.
> 
> Paul Lalli

I have submitted an errata (on file 04-01.plx) to O'Reilly.com

Thanks again Paul!

Best Regards
Staale Flock

-- 
To mail me takeaway the obvious..:o)


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

Date: Wed, 29 Sep 2004 17:07:14 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <slrnclmcgi.k03.tadmc@magna.augustmail.com>

David Filmer <ineverreadanythingsenttome@hotmail.com> wrote:


> my %food_price = ( 'Hotdog' => 1.00, 'Popsicle' => 0.50 );


> I associate curlys with hashes. 


Curlies are overloaded.

Sometimes they are part of a hash access.

Sometimes they create an anonymous hash.

Sometimes they form a BLOCK.

Sometimes they delimit a ${variable} name.

etc...

(And sometimes they form a smiley  :-}  , or is that a "grimacey"? )




> Is there some 
> rationale behind the fact that Perl uses parens to populate a hash in this 
> way?


Perl does not use parens to populate a hash, it uses a "list" to
populate a hash.

Often parens are required to override precedence so that Perl's
parser can recognize it as a list, but parens to not form a list.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 29 Sep 2004 17:08:25 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <slrnclmcip.k03.tadmc@magna.augustmail.com>

Paul Lalli <mritty@gmail.com> wrote:

> ( ) are used to create arrays and hashes.


They are often used to _populate_ arrays and hashes, but they
do not "create" them.


> { } are used to create hash references
> [ ] are used to create array references


Now those _do_ create things...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 30 Sep 2004 00:32:32 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Syntax appears inconsistent - why is this?
Message-Id: <slrnclml10.hv.abigail@alexandra.abigail.nl>

A. Sinan Unur (1usa@llenroc.ude.invalid) wrote on MMMMXLVII September
MCMXCIII in <URL:news:Xns9573A1AC53C5Basu1cornelledu@132.236.56.8>:
}}  "David Filmer" <ineverreadanythingsenttome@hotmail.com> wrote in
}}  news:UjE6d.138341$D%.46143@attbi_s51: 
}}  
}} > I can define a hash thusly (this works):
}} > 
}} > my %food_price = ( 'Hotdog' => 1.00, 'Popsicle' => 0.50 );
}} > 
}} > Or, similarly:
}} > 
}} > my %food = ('H' => {label => 'Hotdog ',  price => 1.00 },
}} >                       'P' => {label => 'Popsicle',  price => 0.50 });
}} > 
}} > But the syntax seems inconsistent to me. I would expect to use curlys
}} > to enclose %food (not parens). I associate curlys with hashes. Is
}} > there some rationale behind the fact that Perl uses parens to populate
}} > a hash in this way? Just curious.
}}  
}}  I am curious too. Did you even bother to read any part of the 
}}  documentation?
}}  
}}  {label => 'Hotdog ',  price => 1.00 } is a reference to an anonymous 
}}  hash, not a hash itself.


That doesn't really answer the question, does it? Clearly from the
example, the poster knows what { } is. He isn't asking what { } is.
He's asking why he has to write %food = ( ... ) and not %food = { ... }.

Saying that { ... } is a reference to a hash doesn't answer that question,
because one had to write %food = ( ... ) long before Perl had references.

The answer is that the parens *aren't* creating a construct. The parens
are just there because of precedence (as assignment has a higher precedence
than the comma operator). To initialize a hash, one assigns a list to it
(just like with arrays). And visa versa, a hash in list context gives you
back a list of its key/value pairs.

    my %food_price = qw !Hotdog 1.00 Popsicle 0.50!;

would have worked as well, and no parens are needed.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'


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

Date: Wed, 29 Sep 2004 17:19:24 -0500
From: "Billy N. Patton" <b-patton@ti.com>
To: KVN Chary <kvnchary@yahoo.com>
Subject: Re: Trailing Spaces -- Format Perl
Message-Id: <415B34EC.5040802@ti.com>

KVN Chary wrote:
> Hello,
> 
> my $var1 = "temp";
> my $var2 = "123";
> my $space = " ";
> 
> format STDOUT =
> @<<<<<<<<< @<<< @<<<<<<<<<<<<<<<<<<<<<<<<<
> $var1,$var2,$space
> .
> 
> I need to put 26 spaces at the end of line. But this code doesn't work?
> How can I do this using FORMAT Perl Command?
> 
> Thanks
> KVN

You might try:
printf "%-8s %-3s ",$var1,$var2
print ' ' x 26 , "\n";

-- 
    ___  _ ____       ___       __  __
   / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
  / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
            /___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com


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

Date: Wed, 29 Sep 2004 17:21:21 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Write filename w/ scalar and bareword
Message-Id: <slrnclmdb1.k03.tadmc@magna.augustmail.com>

mt35 <mt35@linuxmail.org> wrote:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message news:<Xns9573594CF34A5asu1cornelledu@132.236.56.8>...
>> mt35@linuxmail.org (mt35) wrote in news:2763816a.0409290416.1ddc5229
>> @posting.google.com:


>> > my $date = `date "+%m%d%Y"`;

>> To solve your immediate problem, add a 
>> 
>> chomp $date;
> 
> This was the problem...Is my newness to perl painfully obvious yet? ;)


Not at all.

I've been using Perl for mumble,mumble years, and I still
forget to chomp() on occasion.

Your newness to programming itself seems obvious though, as you
did not try some debugging print()s before calling on hundreds
of other people to look at the problem.

(so try some debugging first the next time.)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7193
***************************************


home help back first fref pref prev next nref lref last post