[30238] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1481 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 25 17:01:39 2008

Date: Fri, 25 Apr 2008 14:01:33 -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           Fri, 25 Apr 2008     Volume: 11 Number: 1481

Today's topics:
    Re: The map function <uri@stemsystems.com>
    Re: The map function <gerry@nowhere.ford>
    Re: The map function <simon.chao@gmail.com>
    Re: The map function <tadmc@seesig.invalid>
    Re: The map function <allergic-to-spam@no-spam-allowed.org>
    Re: The map function <uri@stemsystems.com>
    Re: The map function <jurgenex@hotmail.com>
    Re: The map function <gerry@nowhere.ford>
    Re: The map function <gerry@nowhere.ford>
    Re: The map function <gerry@nowhere.ford>
    Re: The map function <gerry@nowhere.ford>
    Re: The map function <noreply@gunnar.cc>
    Re: The map function <jurgenex@hotmail.com>
    Re: The map function <jurgenex@hotmail.com>
    Re: The map function <uri@stemsystems.com>
    Re: The map function <1usa@llenroc.ude.invalid>
    Re: The map function <allergic-to-spam@no-spam-allowed.org>
    Re: The map function <allergic-to-spam@no-spam-allowed.org>
    Re: The map function <cwilbur@chromatico.net>
    Re: The map function <gerry@nowhere.ford>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 22 Apr 2008 20:21:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: The map function
Message-Id: <x7d4ohfxnh.fsf@mail.sysarch.com>

>>>>> "JWK" == John W Krahn <someone@example.com> writes:

  JWK> The syntax error is not related at all to this statement.  Jim Cochrane
  JWK> posted the correct solution.  The problem is that the do {} block
  JWK> following the open() does not end with a semicolon.

  >>> }
  JWK>    ^^^^
  JWK> Missing ; for do {} block.

another reason to avoid do blocks. in a 10k line system i wrote i found
2 uses of do blocks. and in the OP's case the normal open or die/return
is of course the better style. having a large do block after an or is
just insane. an if/then would do the same and be much more normal and
readable if you couldn't use statement modifiers or such.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Tue, 22 Apr 2008 16:26:59 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: The map function
Message-Id: <1208899188_3070@news.newsgroups.com>


"Jim Cochrane" <allergic-to-spam@no-spam-allowed.org> wrote in message 
news:slrng0r3ie.j1a.allergic-to-spam@no-spam-allowed.org...
> On 2008-04-22, Gerry Ford <gerry@nowhere.ford> wrote:

> Change:
>> }
>
> to:
> };
>
> (i.e., missing a ';' - and your code could be formatted better)
Thanks, Jim.  Missing semicolons were the culprit:

#!/usr/bin/perl -w

use strict;
use warnings;

my $killrc = "sample.killrc";
my @filter;
my @list1 = qw( Mon Tu Wed);
    open(FILE, "<$killrc") and do {
        @filter = ();
        foreach (<FILE>) {
            chomp; length or next; /^#/o and next;
            my $pat; eval '$pat = qr/$_/' or do {prompt $@; next};
            push @filter, $pat;
        };
        close(FILE);

};
print @filter;
print @list1;

#  perl mats5.pl 2>text50.txt >text51.txt
__END__
#end script begin output

(?-xism:^From:.*<bad.user@foobar.com>)(?-xism:^Subject:.*MONEY)(?-xism:^Message-ID:.*googlegroups)MonTuWed

#end output show sample.killrc
^From:.*<bad.user@foobar.com>
^Subject:.*MONEY
^Message-ID:.*googlegroups

Any ideas where the ?-xism is coming from?

>> Perl.exe says:
>> syntax error at mats5.pl line 18, near "print"
>
> The compiler was pointing pretty much right at the problem.
I beg to differ.  I snipped this from an actual, working perl program.  How 
do you know which braces need a semicolon after?

sub read_killrc {
    open(FILE, "<$killrc") and do {
        @filter = ();
        foreach (<FILE>) {
            chomp; length or next; /^#/o and next;
            my $pat; eval '$pat = qr/$_/' or do {prompt $@; next};
            push @filter, $pat;
        }
        close(FILE);
    };
}

The error had nothing to do with the print statements, but with a missing 
token several lines before.  At least now I've got output, so I can waddle 
along.
-- 
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell.  The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."

~~  Butch Hancock 




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

Date: Tue, 22 Apr 2008 14:30:40 -0700 (PDT)
From: nolo contendere <simon.chao@gmail.com>
Subject: Re: The map function
Message-Id: <a2fe5a2d-c7d7-47a8-8a6f-a94f3e295703@8g2000hse.googlegroups.com>

On Apr 22, 5:26=A0pm, "Gerry Ford" <ge...@nowhere.ford> wrote:
> "Jim Cochrane" <allergic-to-s...@no-spam-allowed.org> wrote in message
>
> news:slrng0r3ie.j1a.allergic-to-spam@no-spam-allowed.org...
>
> > On 2008-04-22, Gerry Ford <ge...@nowhere.ford> wrote:
> > Change:
> >> }
>
> > to:
> > };
>
> > (i.e., missing a ';' - and your code could be formatted better)
>
> Thanks, Jim. =A0Missing semicolons were the culprit:
>
> #!/usr/bin/perl -w
>
> use strict;
> use warnings;
>
> my $killrc =3D "sample.killrc";
> my @filter;
> my @list1 =3D qw( Mon Tu Wed);
> =A0 =A0 open(FILE, "<$killrc") and do {
> =A0 =A0 =A0 =A0 @filter =3D ();
> =A0 =A0 =A0 =A0 foreach (<FILE>) {
> =A0 =A0 =A0 =A0 =A0 =A0 chomp; length or next; /^#/o and next;
> =A0 =A0 =A0 =A0 =A0 =A0 my $pat; eval '$pat =3D qr/$_/' or do {prompt $@; =
next};
> =A0 =A0 =A0 =A0 =A0 =A0 push @filter, $pat;
> =A0 =A0 =A0 =A0 };
> =A0 =A0 =A0 =A0 close(FILE);
>
> };
>
> print @filter;
> print @list1;
>
> # =A0perl mats5.pl 2>text50.txt >text51.txt
> __END__
> #end script begin output
>
> (?-xism:^From:.*<bad.u...@foobar.com>)(?-xism:^Subject:.*MONEY)(?-xism:^Me=
ssage-ID:.*googlegroups)MonTuWed
>
> #end output show sample.killrc
> ^From:.*<bad.u...@foobar.com>
> ^Subject:.*MONEY
> ^Message-ID:.*googlegroups
>
> Any ideas where the ?-xism is coming from?

those are from the compiled regex. check out the effect of qr// on a
simple regex by printing it.


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

Date: Tue, 22 Apr 2008 06:52:52 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: The map function
Message-Id: <slrng0rkck.h5g.tadmc@tadmc30.sbcglobal.net>

Gerry Ford <gerry@nowhere.ford> wrote:

> How does a person invoke 
> the debugger?


   perldoc -q debug

       How do I debug my Perl programs?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 23 Apr 2008 03:08:00 +0200 (CEST)
From: Jim Cochrane <allergic-to-spam@no-spam-allowed.org>
Subject: Re: The map function
Message-Id: <slrng0t2vg.sbv.allergic-to-spam@no-spam-allowed.org>

On 2008-04-22, Gerry Ford <gerry@nowhere.ford> wrote:
>
> "Jim Cochrane" <allergic-to-spam@no-spam-allowed.org> wrote in message 
> news:slrng0r3ie.j1a.allergic-to-spam@no-spam-allowed.org...
>> On 2008-04-22, Gerry Ford <gerry@nowhere.ford> wrote:
>
>> Change:
>>> }
>>
>> to:
>> };
>>
>> (i.e., missing a ';' - and your code could be formatted better)
> Thanks, Jim.  Missing semicolons were the culprit:
>
> #!/usr/bin/perl -w
>
> use strict;
> use warnings;
>
> my $killrc = "sample.killrc";
> my @filter;
> my @list1 = qw( Mon Tu Wed);
>     open(FILE, "<$killrc") and do {
>         @filter = ();
>         foreach (<FILE>) {
>             chomp; length or next; /^#/o and next;
>             my $pat; eval '$pat = qr/$_/' or do {prompt $@; next};
>             push @filter, $pat;
>         };
>         close(FILE);
>
> };
> print @filter;
> print @list1;
>
> #  perl mats5.pl 2>text50.txt >text51.txt
> __END__
> #end script begin output
>
> (?-xism:^From:.*<bad.user@foobar.com>)(?-xism:^Subject:.*MONEY)(?-xism:^Message-ID:.*googlegroups)MonTuWed
>
> #end output show sample.killrc
> ^From:.*<bad.user@foobar.com>
> ^Subject:.*MONEY
> ^Message-ID:.*googlegroups
>
> Any ideas where the ?-xism is coming from?
>
>>> Perl.exe says:
>>> syntax error at mats5.pl line 18, near "print"
>>
>> The compiler was pointing pretty much right at the problem.
> I beg to differ.  I snipped this from an actual, working perl program.  How 
> do you know which braces need a semicolon after?

If I remember correctly, line 18 (from your error message) was either
the offending line with the close curly brace missing the ';' or the
line (print ...) below it.  So you know where to look because of the
line # in the error message.  Of course, now that you know that 'do {}'
blocks need a semicolon after them (right?), you know to look for that
now, too.  (Of course, compile error messages will not always report a
line number that is at or very close to the actual problem in the code.)

>
> sub read_killrc {
>     open(FILE, "<$killrc") and do {
>         @filter = ();
>         foreach (<FILE>) {
>             chomp; length or next; /^#/o and next;
>             my $pat; eval '$pat = qr/$_/' or do {prompt $@; next};
>             push @filter, $pat;
>         }
>         close(FILE);
>     };
> }
>
> The error had nothing to do with the print statements, but with a missing 
> token several lines before.  At least now I've got output, so I can waddle 
> along.


-- 



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

Date: Wed, 23 Apr 2008 08:36:55 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: The map function
Message-Id: <x7d4oh6k7s.fsf@mail.sysarch.com>

>>>>> "JC" == Jim Cochrane <allergic-to-spam@no-spam-allowed.org> writes:

  >> do you know which braces need a semicolon after?

  JC> If I remember correctly, line 18 (from your error message) was either
  JC> the offending line with the close curly brace missing the ';' or the
  JC> line (print ...) below it.  So you know where to look because of the
  JC> line # in the error message.  Of course, now that you know that 'do {}'
  JC> blocks need a semicolon after them (right?), you know to look for that

actually do blocks are just expressions and the statement they might be
in will need a ; (and of course in perl ; is a statement separator and
not a terminator). in this case the do block was the end of the
statement and needed a ; before the print. an if block (or other flow
control block isn't a statement so they don't need ; after them.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Wed, 23 Apr 2008 11:08:46 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: The map function
Message-Id: <h06u04tpskpq5tqhr2tcsc28fr0ibnergt@4ax.com>

Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "JC" == Jim Cochrane <allergic-to-spam@no-spam-allowed.org> writes:
>
>  >> do you know which braces need a semicolon after?
>
>  JC> If I remember correctly, line 18 (from your error message) was either
>  JC> the offending line with the close curly brace missing the ';' or the
>  JC> line (print ...) below it.  So you know where to look because of the
>  JC> line # in the error message.  Of course, now that you know that 'do {}'
>  JC> blocks need a semicolon after them (right?), you know to look for that
>
>actually do blocks are just expressions and the statement they might be
>in will need a ; (and of course in perl ; is a statement separator and
>not a terminator). in this case the do block was the end of the
>statement and needed a ; before the print. an if block (or other flow
>control block isn't a statement so they don't need ; after them.

Another reason to avoid do{} blocks that are dozens of lines long. At
the end of such a block you surely have forgotten, if it is a flow
controll block or an expression.

jue


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

Date: Wed, 23 Apr 2008 19:53:27 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: The map function
Message-Id: <1208997977_3082@news.newsgroups.com>


"Jürgen Exner" <jurgenex@hotmail.com> wrote in message 
news:21mr04pro5k3sqjbebv5g2jq5i0doq42t3@4ax.com...
> "Gerry Ford" <gerry@nowhere.ford> wrote:


>>Perl.exe says:
>>syntax error at mats5.pl line 18, near "print"
>>Execution of mats5.pl aborted due to compilation errors.
>
> Man, dude!!!  How are we supposed to guess??? You could have told us
> that your beef is not with the functionality of print() but with a
> syntax error in that program! Thank you very much for throwing around
> red herrings.

My problem was that I thought I had a working script before I added the 
print statements.  At this point, I'm simply very error-prone.  This is my 
current version of this script, that I think addresses your criticisms:

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper qw( Dumper);

my $killrc = "kill.rc";
my @filter;
open (FILE, "<", $killrc) or die ("Cannot open $killrc: $!");

@filter = ();
foreach (<FILE>) {
chomp;
next unless length;
next if  /^#/o;
my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next};
push @filter, $pat;

close(FILE);

}
print @filter;

#print STDERR "The list is " . Dumper( @list ) . "\n";

__END__

How would you indent this?

> However, I wonder what you are trying to achive by using eval in the
> first place. I don't see any need for it.
I could just omit it?

-- 
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell.  The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."

~~  Butch Hancock 




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

Date: Wed, 23 Apr 2008 20:02:27 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: The map function
Message-Id: <1208998517_3083@news.newsgroups.com>


"Jim Cochrane" <allergic-to-spam@no-spam-allowed.org> wrote in message 
news:slrng0t2vg.sbv.allergic-to-spam@no-spam-allowed.org...

>> I beg to differ.  I snipped this from an actual, working perl program. 
>> How
>> do you know which braces need a semicolon after?
>
> If I remember correctly, line 18 (from your error message) was either
> the offending line with the close curly brace missing the ';' or the
> line (print ...) below it.  So you know where to look because of the
> line # in the error message.  Of course, now that you know that 'do {}'
> blocks need a semicolon after them (right?), you know to look for that
> now, too.  (Of course, compile error messages will not always report a
> line number that is at or very close to the actual problem in the code.)

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper qw( Dumper);

my $killrc = "kill.rc";
my @filter;
open (FILE, "<", $killrc) or die ("Cannot open $killrc: $!");

@filter = ();
foreach (<FILE>) {
chomp;
next unless length;
next if  /^#/o;
my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next};
push @filter, $pat;

close(FILE);

}
print @filter;

#print STDERR "The list is " . Dumper( @list ) . "\n";

__END__

I'm still confused on the whole }; thing.  With this version, I've 
eliminated the the do{};  If I put a semicolon after the foreach close curly 
brace, I get no change in behavior in the program. ??

-- 
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell.  The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."

~~  Butch Hancock




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

Date: Wed, 23 Apr 2008 20:08:12 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: The map function
Message-Id: <1208998863_3084@news.newsgroups.com>


"Tad J McClellan" <tadmc@seesig.invalid> wrote in message 
news:slrng0rkck.h5g.tadmc@tadmc30.sbcglobal.net...
> Gerry Ford <gerry@nowhere.ford> wrote:
>
>> How does a person invoke
>> the debugger?
>
>
>   perldoc -q debug
>
>       How do I debug my Perl programs?


#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper qw( Dumper);

my $killrc = "kill.rc";
my @filter;
open (FILE, "<", $killrc) or die ("Cannot open $killrc: $!");

@filter = ();
foreach (<FILE>) {
chomp;
next unless length;
next if  /^#/o;
my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next};
push @filter, $pat;

close(FILE);

};
print @filter;

#print STDERR "The list is " . Dumper( @list ) . "\n";


__END__

In perldoc -q debug, they commend the use of Data::Dumper.  I mimicked the 
syntax in the but perlexe thinks I need to have an explicit package instead. 
What gives?
-- 
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell.  The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."

~~  Butch Hancock




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

Date: Wed, 23 Apr 2008 20:27:40 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: The map function
Message-Id: <1209000030_3085@news.newsgroups.com>


"Uri Guttman" <uri@stemsystems.com> wrote in message 
news:x7bq42v97j.fsf@mail.sysarch.com...
>>>>>> "GF" == Gerry Ford <gerry@nowhere.ford> writes:
>

[snipped and re-ordered]
> my return calls IMPLY A SUB is surrounding it. of course it won't work
> as shown. jeez, i can't hold your hand and also blow your nose. think
> about the code and don't just copy/run it.

You wouldn't want to be anywhere near my infirmities today.  Stomach flu.
#!/usr/bin/perl

use strict;
use warnings;

my $killrc = "sample.killrc";

sub read_killrc {
return unless open(my $file, "<$killrc") ;
return map {
            /^([^#]+)#?$/ &&
            eval{ qr/$1/} || prompt $@, ()
} <$file> ;
}
read_killrc;


__END__

So, how do I adapt this now to take advantage of the return values of map? 
I no longer have the option of writing
print @filter;
?

>  GF> #  perl mats5.pl 2>text50.txt >text51.txt
>
> why the redirect of stderr? there is no stderr output. and what is in
> the prompt sub?

#  perl mats7.pl 2>text50.txt >text51.txt
This statement is what I call "the goocher."  It keeps track of what version 
I'm running and has a means to redirect stdout and stderr.  I should 
capitalize those.  I copy and paste these into the command line.

What kind of name is Uri?
-- 
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell.  The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."

~~  Butch Hancock 




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

Date: Thu, 24 Apr 2008 03:30:48 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: The map function
Message-Id: <67a62qF2oard5U1@mid.individual.net>

Gerry Ford wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message 
> news:21mr04pro5k3sqjbebv5g2jq5i0doq42t3@4ax.com...
>> However, I wonder what you are trying to achive by using eval in the
>> first place. I don't see any need for it.
>
> I could just omit it?

It's up to you; I for one do see a need for it: It prevents a fatal 
error for the case a line is not a valid regular expression.

C:\home>type test.pl
my @filter;
while (<DATA>) {
     chomp;
     next unless length;
     next if  /^#/o;
     my $pat;
     eval '$pat = qr($_)' or do { warn $@; next };
     push @filter, $pat;
}
print "$_\n" foreach @filter;

__DATA__
\w+).+?
\s+

C:\home>test.pl
Unmatched ) in regex; marked by <-- HERE in m/\w+) <-- HERE .+?/ at 
(eval 1) line 1, <DATA> line 1.
(?-xism:\s+)

C:\home>

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


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

Date: Thu, 24 Apr 2008 01:47:13 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: The map function
Message-Id: <6pov04dlokosh89u1pfl841ri0q9bgfh9e@4ax.com>

"Gerry Ford" <gerry@nowhere.ford> wrote:
>"Jürgen Exner" <jurgenex@hotmail.com> wrote in message 
>> Man, dude!!!  How are we supposed to guess??? You could have told us
>> that your beef is not with the functionality of print() but with a
>> syntax error in that program! Thank you very much for throwing around
>> red herrings.
>
>My problem was that I thought I had a working script before I added the 
>print statements.  At this point, I'm simply very error-prone. 

Then it is even more important to follow standard procedures for your
own and others sake:

1: what is the expected behaviour?
2: what is the observed behaviour?
3: what code is producing this behaviour?
4: what data is producing this behaviour?
Those 4 elements are vital for any reasonable investigation. 

You supplied 3, were vague about 1, and didn't tell anything about 2 or
4, so people had to use crystal balls and tea leaves to guess. And of
course they guessed wrong.

> This is my 
>current version of this script, that I think addresses your criticisms:

[most of the code snipped]
You are still omitting a precise description of what you expect(1), what
you observe (2), and data to run your sample code (4).

>my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next};

You still got an 'interesting' do{} sitting around.

>How would you indent this?

I would open the file in my favourite editor and run a "indent-region"
command.

>> However, I wonder what you are trying to achive by using eval in the
>> first place. I don't see any need for it.
>I could just omit it?

Think! What is it that you are trying to achieve by using the eval()?
You didn't tell us. So how can we answer your question? If you don't
tell us then we cannot know what you are trying to do with that eval and
therefore cannot tell if the eval serves any purpose to achieve that
goal or not.

jue 


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

Date: Thu, 24 Apr 2008 02:09:51 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: The map function
Message-Id: <0mpv04lchbf7lm0b9a9rh5mafikbop6qqf@4ax.com>

"Gerry Ford" <gerry@nowhere.ford> wrote:
[...]
>my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next};
[...]

>I'm still confused on the whole }; thing.  

There is no }; thing. Understanding this is your problem.

There are 'blocks' that are enclosed in curly braces {.....}. Period.

And then there are statements. Individual statements are separated by a
; in Perl, i.e. between any two statements you have to write a ;.

In your original progam you had [reformatted to make it more obvious]
    open(FILE, "<$killrc") and 
	do {SomeVeryLongWhatever} print @filter;

What you meant was 
    open(FILE, "<$killrc") and 
	do {SomeVeryLongWhatever};
    print @filter;

If you want print() to be a new statement, then you have to place a
semicolon between the preceeding statement and the print(). If you don't
then you will get that syntax error because perl had to assume that you
are continuing the preceeding statement. After all, it could have been
that you wanted to add 5 to the result of do, something like 

	do {SomeVeryLongWhatever} + 5;

which is perfectly legal. The only way for perl to know that a new
statement is starting is if you put that semicolon there.
 
>With this version, I've eliminated the the do{}; 

No, you haven't. See the one line of code I quoted above.

> If I put a semicolon after the foreach close curly 
>brace, I get no change in behavior in the program. ??

That's just a surplus empty statement. Perl doesn't care if you create a
dozen  or a million.

jue


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

Date: Thu, 24 Apr 2008 03:30:47 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: The map function
Message-Id: <x7ve28x72v.fsf@mail.sysarch.com>

>>>>> "GF" == Gerry Ford <gerry@nowhere.ford> writes:

  GF> "Uri Guttman" <uri@stemsystems.com> wrote in message 
  GF> news:x7bq42v97j.fsf@mail.sysarch.com...
  >>>>>>> "GF" == Gerry Ford <gerry@nowhere.ford> writes:
  >> 
  GF> my $killrc = "sample.killrc";

  GF> sub read_killrc {
  GF> return unless open(my $file, "<$killrc") ;
  GF> return map {
  GF>             /^([^#]+)#?$/ &&
  GF>             eval{ qr/$1/} || prompt $@, ()
  GF> } <$file> ;
  GF> }

some formatting/indenting  will help there.
  GF> read_killrc;

great! you just tossed away the results of the call.

  GF> So, how do I adapt this now to take advantage of the return values of map? 
  GF> I no longer have the option of writing
  GF> print @filter;

do you think print only takes an array? what does the above sub return?
A LIST generated by the map. so print it! you can print ANY expression
or list of expressions. 

print read_killrc() ;

was that so hard? even with the flu you should have gotten that!

  GF> #  perl mats5.pl 2>text50.txt >text51.txt

  >> why the redirect of stderr? there is no stderr output. and what is in
  >> the prompt sub?

  GF> #  perl mats7.pl 2>text50.txt >text51.txt
  GF> This statement is what I call "the goocher."  It keeps track of what version 
  GF> I'm running and has a means to redirect stdout and stderr.  I should 
  GF> capitalize those.  I copy and paste these into the command line.

that still makes no sense. the script (or at least the code you have
shown) doesn't print to STDERR. 

  GF> What kind of name is Uri?

my kind.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Thu, 24 Apr 2008 04:15:07 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: The map function
Message-Id: <Xns9A8A28F5F16Basu1cornelledu@127.0.0.1>

>>>>>> "GF" == Gerry Ford <gerry@nowhere.ford> writes:

I find this constant changing of posting ids pretty annoying. Please 
decide if you are Wade Ward or zaxfux or whatever it is and stick with it. 
In any case, you have been re-added to my killfile under this new identity 
and I cannot believe I have been fooled into responding to your question.

>   GF> What kind of name is Uri?

What is the point of picking on other people's names when you can't even 
decide what your own name is?

Sinan

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

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Thu, 24 Apr 2008 07:24:29 +0200 (CEST)
From: Jim Cochrane <allergic-to-spam@no-spam-allowed.org>
Subject: Re: The map function
Message-Id: <slrng106cf.n7i.allergic-to-spam@no-spam-allowed.org>

On 2008-04-23, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "JC" == Jim Cochrane <allergic-to-spam@no-spam-allowed.org> writes:
>
>  >> do you know which braces need a semicolon after?
>
>  JC> If I remember correctly, line 18 (from your error message) was either
>  JC> the offending line with the close curly brace missing the ';' or the
>  JC> line (print ...) below it.  So you know where to look because of the
>  JC> line # in the error message.  Of course, now that you know that 'do {}'
>  JC> blocks need a semicolon after them (right?), you know to look for that
>
> actually do blocks are just expressions and the statement they might be
> in will need a ; (and of course in perl ; is a statement separator and
> not a terminator). in this case the do block was the end of the
> statement and needed a ; before the print. an if block (or other flow
> control block isn't a statement so they don't need ; after them.
>
> uri
>

Thanks for the clarification.

-- 



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

Date: Thu, 24 Apr 2008 07:29:26 +0200 (CEST)
From: Jim Cochrane <allergic-to-spam@no-spam-allowed.org>
Subject: Re: The map function
Message-Id: <slrng106lo.n7i.allergic-to-spam@no-spam-allowed.org>

On 2008-04-24, Jürgen Exner <jurgenex@hotmail.com> wrote:
> "Gerry Ford" <gerry@nowhere.ford> wrote:
> [...]
>>my $pat; eval ('$pat = qr/$_/') or do {prompt $@; next};
> [...]
>
>>I'm still confused on the whole }; thing.  
>
> [good explanation deleted]

Also, see Uri Guttman's response to my post for further elaboration
(and correction to my somewhat misleading statement that you need a
semicolon after a do {} block).

-- 



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

Date: Thu, 24 Apr 2008 08:13:53 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: The map function
Message-Id: <8663u7h2m6.fsf@mithril.chromatico.net>

>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> writes:

    ASU> I find this constant changing of posting ids pretty
    ASU> annoying. Please decide if you are Wade Ward or zaxfux or
    ASU> whatever it is and stick with it.  In any case, you have been
    ASU> re-added to my killfile under this new identity and I cannot
    ASU> believe I have been fooled into responding to your question.

Pay attention to the posting style - it's consistent.

(I suspect his inability to write or program coherently and his
inability to stick to the same posting ID are both symptoms of a
deeper malaise.)

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 24 Apr 2008 20:50:02 -0500
From: "Gerry Ford" <gerry@nowhere.ford>
Subject: Re: The map function
Message-Id: <1209087769_3109@news.newsgroups.com>


"Charlton Wilbur" <cwilbur@chromatico.net> wrote in message 
news:8663u7h2m6.fsf@mithril.chromatico.net...
>>>>>> "ASU" == A Sinan Unur <1usa@llenroc.ude.invalid> writes:
>
>    ASU> I find this constant changing of posting ids pretty
>    ASU> annoying. Please decide if you are Wade Ward or zaxfux or
>    ASU> whatever it is and stick with it.  In any case, you have been
>    ASU> re-added to my killfile under this new identity and I cannot
>    ASU> believe I have been fooled into responding to your question.
>
> Pay attention to the posting style - it's consistent.
>
> (I suspect his inability to write or program coherently and his
> inability to stick to the same posting ID are both symptoms of a
> deeper malaise.)

#!/usr/bin/perl

use strict;
use warnings;

my $killrc = "sample.killrc";
my @filter;

sub read_killrc {
return unless open(my $file, "<$killrc") ;
return map {
            /^([^#]+)#?$/ &&
            eval{ qr/$1/} || prompt $@, ()
} <$file> ;
}
print read_killrc;

while (<DATA>) {
     chomp;
     next unless length;
     next if  /^#/o;
     my $pat;
     eval '$pat = qr($_)' or do { warn $@; next };
     push @filter, $pat;
}
print "$_\n" foreach @filter;

__DATA__
^From:.*cbfalconer Sinan
^Subject:.*memset
^Message-ID:.*googlegroups
\w+).+?
\s+((


__END__


#  perl mats8.pl 2>text50.txt >text51.txt

In this thread, I compared and contrasted the use of the map function as 
opposed to foreach, providing working Perl as an end-product.  Furthermore, 
I stumbled on a way to test regex's.  What did you do?  You replied to a 
person who was wrong--Wade is my google identity, which I'd only use if I 
were traveling--and I've been home for the entire month, and reinforced the 
chippiness in usenet.

What do your posts say about the topic at hand?

-- 
"Life in Lubbock, Texas, taught me two things: One is that God loves you
and you're going to burn in hell.  The other is that sex is the most
awful, filthy thing on earth and you should save it for someone you love."

~~  Butch Hancock 




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

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 V11 Issue 1481
***************************************


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