[29350] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 594 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 28 14:10:13 2007

Date: Thu, 28 Jun 2007 11:09:10 -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           Thu, 28 Jun 2007     Volume: 11 Number: 594

Today's topics:
        "Convert" perl command line to simple script  bluez34me@gmail.com
    Re: "Convert" perl command line to simple script <jurgenex@hotmail.com>
    Re: "Convert" perl command line to simple script <mritty@gmail.com>
    Re: "Convert" perl command line to simple script <mritty@gmail.com>
    Re: "Convert" perl command line to simple script <mritty@gmail.com>
    Re: "Convert" perl command line to simple script <rvtol+news@isolution.nl>
    Re: "Out of memory!" ??? <jurgenex@hotmail.com>
        coarse-grained parallel processing of a for-loop <guba@vi-anec.de>
    Re: coarse-grained parallel processing of a for-loop <peter@makholm.net>
    Re: coarse-grained parallel processing of a for-loop <rvtol+news@isolution.nl>
    Re: coarse-grained parallel processing of a for-loop xhoster@gmail.com
    Re: date parts in one step <tadmc@seesig.invalid>
    Re: date parts in one step <baxter.brad@gmail.com>
    Re: date parts in one step <hjp-usenet2@hjp.at>
        DBIx::Simple, fails with no error (not CGI this time!) <justin.0706@purestblue.com>
    Re: DBIx::Simple, fails with no error (not CGI this tim <mritty@gmail.com>
    Re: FAQ 1.6 What is perl6? <art@xiotek.com>
        map woes <seven.reeds@gmail.com>
    Re: map woes <glennj@ncf.ca>
    Re: map woes <dummy@example.com>
    Re: map woes <seven.reeds@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Jun 2007 15:44:07 -0000
From:  bluez34me@gmail.com
Subject: "Convert" perl command line to simple script
Message-Id: <1183045447.850398.70810@j4g2000prf.googlegroups.com>

I've looked over the Perl FAQs, this list, and done a good bit of
googling, but haven't found an answer to this...

I have some commands that I issue via the command line that I want to
convert to scripts, but as a complete Perl newb, I haven't a clue how
to go about it. I was hoping that there was some simple way, like
saving the text as a .pl and then calling perl <script>.pl, but
obviously it doesn't work quite that way.

Here's an example of a script that I'm running to clean up html pages
that I'm generating automatically:

perl -pi -e 's/..\index/index/g' *.html

Is there some "standard" and simple way to get this into script form,
or do I need to write a complete script that handles looping through
the files, does the regex handling and all that?

Any help greatly appreciated.



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

Date: Thu, 28 Jun 2007 16:28:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: "Convert" perl command line to simple script
Message-Id: <GkRgi.5382$ss5.3768@trndny03>

bluez34me@gmail.com wrote:
> Here's an example of a script that I'm running to clean up html pages
> that I'm generating automatically:
>
> perl -pi -e 's/..\index/index/g' *.html
>
> Is there some "standard" and simple way to get this into script form,
> or do I need to write a complete script that handles looping through
> the files, does the regex handling and all that?

Well, let's check what those command line parameters do (from perldoc 
perlrun):
    -e *commandline*
         may be used to enter one line of program. If -e is given, Perl will
         not look for a filename in the argument list. Multiple -e commands
         may be given to build up a multi-line script. Make sure to use
         semicolons where you would in a normal program.

Ok, that's trivial.

    -i[*extension*]
         specifies that files processed by the "<>" construct are to be
         edited in-place. It does this by renaming the input file, opening
         the output file by the original name, and selecting that output
         file as the default for print() statements. [...]

Seems this is one you will have to code yourself.

    -p   causes Perl to assume the following loop around your program, which
         makes it iterate over filename arguments somewhat like sed:

           LINE:
             while (<>) {
                 ...             # your program goes here
             } continue {
                 print or die "-p destination: $!\n";
             }

This one you will have to implement yourself, too (although that should be 
rather trivial given this template).

And of course you will need to loop through all the file names resulting 
from the shell glob expansion.

jue 




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

Date: Thu, 28 Jun 2007 09:47:23 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: "Convert" perl command line to simple script
Message-Id: <1183049243.335649.267320@q69g2000hsb.googlegroups.com>

On Jun 28, 11:44 am, bluez3...@gmail.com wrote:
> I've looked over the Perl FAQs, this list, and done a good bit of
> googling, but haven't found an answer to this...

perldoc perlrun
would be a good place to look.

> I have some commands that I issue via the command line that I want to
> convert to scripts, but as a complete Perl newb, I haven't a clue how
> to go about it. I was hoping that there was some simple way, like
> saving the text as a .pl and then calling perl <script>.pl, but
> obviously it doesn't work quite that way.

sure it does.  What makes you think it's  "obvious" that it doesn't?
The code provided to the -e option goes into your main file.  Any
other options are given after the shebang.

> Here's an example of a script that I'm running to clean up html pages
> that I'm generating automatically:
>
> perl -pi -e 's/..\index/index/g' *.html
>
> Is there some "standard" and simple way to get this into script form,
> or do I need to write a complete script that handles looping through
> the files, does the regex handling and all that?

You can see what those options are doing either by investigating in
perldoc perlrun, as I already suggested, or by using the Deparse
module:

$ perl -MO=Deparse -pi -e 's/..\index/index/g' *.html
LINE: while (defined($_ = <ARGV>)) {
    s/..index/index/g;
}
continue {
    print $_;
}

If you don't want to put the -pi on the shebang line, just throw those
four lines of code into your .pl file, add the shebang, strict, and
warnings to the top, and call your file:
myfile.pl *.html

Paul Lalli



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

Date: Thu, 28 Jun 2007 09:49:46 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: "Convert" perl command line to simple script
Message-Id: <1183049386.863156.125760@o61g2000hsh.googlegroups.com>

On Jun 28, 12:28 pm, "J=FCrgen Exner" <jurge...@hotmail.com> wrote:

>     -i[*extension*]
>          specifies that files processed by the "<>" construct are to be
>          edited in-place. It does this by renaming the input file, opening
>          the output file by the original name, and selecting that output
>          file as the default for print() statements. [...]
>
> Seems this is one you will have to code yourself.


Not really.
$ perldoc -q -i
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq5.pod
     How can I use Perl's "-i" option from within a program?

Paul Lalli




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

Date: Thu, 28 Jun 2007 09:50:46 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: "Convert" perl command line to simple script
Message-Id: <1183049446.470998.271250@m36g2000hse.googlegroups.com>

On Jun 28, 12:47 pm, Paul Lalli <mri...@gmail.com> wrote:

> $ perl -MO=Deparse -pi -e 's/..\index/index/g' *.html
> LINE: while (defined($_ = <ARGV>)) {
>     s/..index/index/g;}
>
> continue {
>     print $_;
>
> }

Hrm.  Accidentally truncated my output.... the start of that code
should include
BEGIN { $^I = ""; }

which is the effect of the -i parameter.

Paul Lalli



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

Date: Thu, 28 Jun 2007 19:47:31 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: "Convert" perl command line to simple script
Message-Id: <f613b2.10c.1@news.isolution.nl>

bluez34me@gmail.com schreef:

> perl -pi -e 's/..\index/index/g' *.html

That "..\i" most l\ikely doesn't mean what you th\ink \it means\. 

(see perldoc -f quotemeta) 

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Thu, 28 Jun 2007 16:42:25 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: "Out of memory!" ???
Message-Id: <RxRgi.13994$XH5.6398@trndny02>

[Please do not full-quote but shorten the quoted text to the relevant 
portion]
[Please do not top-post, trying to correct]
Jie wrote:
> On Jun 27, 3:10 pm, "Jürgen Exner" <jurge...@hotmail.com> wrote:
>> Solution: rewrite your code in a clean way that does not use symbolic
>> references (which are evil to begin with).
> I do not know if symbolic reference means Global reference.

No, they are different things. Symbolic describes _how_ they are created, 
while globel describes _where_ they are created.
Symbolic reference can only be created globally, but global references (or 
variables) are only symbolic if you use poor coding style.

> And
> therefore I should try to define local variable. This might be a very
> naive question. Do I just add "my" to define a local variable such as
> below:

Well, using local variables instead of global variables is certainly 
helpful, too, but it has nothing to do with symbolic references. Even if you 
define the reference itself as a local variable and use it to create a 
symbolic reference, then the target data structure of that reference is 
still a global object.

You may want to read up on
    perldoc -q "variable name"
"How can I use a variable as a variable name?"

jue 




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

Date: Thu, 28 Jun 2007 03:44:44 -0700
From:  "guba@vi-anec.de" <guba@vi-anec.de>
Subject: coarse-grained parallel processing of a for-loop
Message-Id: <1183027484.425006.126060@m36g2000hse.googlegroups.com>

Hello,

I am searching for an easy way for a coarse-grained
parallel processing of a for-loop (image processing
with PerlMagick/Win on a QuadCore). Because no
communication is nedded the for-loop

for ($i = $count_min; $i =< $count_max; $i++) {
	read selected source images
    image composing
    write result image on HD
};

could theoretically be splitted in 4 loops

    $count_min..int($count_max/4)
    int($count_max/4)+1..int($count_max/2)
    int($count_max/2)+1..int(3*$count_max/4)
    int(3*$count_max/4)+1..$count_max

that are processed in parallel (each on a Core).

cpan offers 300 results for "parallel" but I don't
know where to start. Thank you very much for hints!

Guenter



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

Date: Thu, 28 Jun 2007 11:00:35 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: coarse-grained parallel processing of a for-loop
Message-Id: <87r6nwtkbw.fsf@makholm.net>

"guba@vi-anec.de" <guba@vi-anec.de> writes:

> I am searching for an easy way for a coarse-grained
> parallel processing of a for-loop (image processing
> with PerlMagick/Win on a QuadCore). Because no
> communication is nedded the for-loop

I don't know if Win32 is a problem, but I have used
Parallel::ForkManager for something alike

use Parallel::ForkManager;

my $pm = new Parallel::ForkManager($MAX_PROCESSES);
for $i ($count_min .. $count_max) {
    my $pid = $pma->start and next;

    read selected source images
    image composing
    write result image on HD

    $pm->finish;
}
$pm->wait_all_children;

But taht gives you no way of communication from within the loop to the
main process.

> could theoretically be splitted in 4 loops
>
>     $count_min..int($count_max/4)
>     int($count_max/4)+1..int($count_max/2)
>     int($count_max/2)+1..int(3*$count_max/4)
>     int(3*$count_max/4)+1..$count_max

If all jobs are of equal length this would be ok but otherwise you
would be better of with some sort of work queue. 

//Makholm


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

Date: Thu, 28 Jun 2007 19:50:08 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: coarse-grained parallel processing of a for-loop
Message-Id: <f613kj.1d4.1@news.isolution.nl>

guba@vi-anec.de schreef:

> I am searching for an easy way for a coarse-grained
> parallel processing of a for-loop (image processing
> with PerlMagick/Win on a QuadCore). Because no
> communication is nedded the for-loop
> 
> for ($i = $count_min; $i =< $count_max; $i++) {
> read selected source images
>     image composing
>     write result image on HD
> };
> 
> could theoretically be splitted in 4 loops
> 
>     $count_min..int($count_max/4)
>     int($count_max/4)+1..int($count_max/2)
>     int($count_max/2)+1..int(3*$count_max/4)
>     int(3*$count_max/4)+1..$count_max

See also the % operator (read `perldoc perlop`).

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: 28 Jun 2007 18:03:04 GMT
From: xhoster@gmail.com
Subject: Re: coarse-grained parallel processing of a for-loop
Message-Id: <20070628140306.628$dX@newsreader.com>

"guba@vi-anec.de" <guba@vi-anec.de> wrote:
> Hello,
>
> I am searching for an easy way for a coarse-grained
> parallel processing of a for-loop (image processing
> with PerlMagick/Win on a QuadCore). Because no
> communication is nedded the for-loop
>
> for ($i = $count_min; $i =< $count_max; $i++) {
>         read selected source images
>     image composing
>     write result image on HD
> };

Parallel::ForkManager might work well for this.  It will do one fork
for each item in count_max (but not all at once, of course), so if the work
load for each individual image is very light, then the overhead of the
forking might come to dominate the workload.  But I've never tried it on
Windows, so I don't know how it works there.

>
> could theoretically be splitted in 4 loops
>
>     $count_min..int($count_max/4)
>     int($count_max/4)+1..int($count_max/2)
>     int($count_max/2)+1..int(3*$count_max/4)
>     int(3*$count_max/4)+1..$count_max
>
> that are processed in parallel (each on a Core).

I frequently do something this like this, too, when each individual item
is light weight.  But I don't know of any CPAN modules to facilitate it.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 28 Jun 2007 10:54:14 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: date parts in one step
Message-Id: <slrnf874lt.f9m.tadmc@tadmc30.sbcglobal.net>

Petr Vileta <stoupa@practisoft.cz> wrote:
> Brad Baxter wrote:
>> On Jun 24, 10:08 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
>>> Function 1 : 37 seconds
>>> Function 2 : 52 seconds
>>> Function 3 : 44 seconds
>>
>> So, given that it's a line of code that you'll execute exactly once,
>> it looks like a toss-up to me.  :-)
> Sorry, English is my second language and is pretty poor - I don't understand 
> you.


   http://en.wiktionary.org/wiki/Toss-up


So Brad was saying that it makes no difference which one is chosen.


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


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

Date: Thu, 28 Jun 2007 13:18:03 -0000
From:  Brad Baxter <baxter.brad@gmail.com>
Subject: Re: date parts in one step
Message-Id: <1183036683.688131.129730@q69g2000hsb.googlegroups.com>

On Jun 28, 5:23 am, Ian Wilson <scoblo...@infotop.co.uk> wrote:
> Petr Vileta wrote:
> > Brad Baxter wrote:
>
> >> On Jun 24, 10:08 am, "Petr Vileta" <sto...@practisoft.cz> wrote:
>
> >>> Function 1 : 37 seconds
> >>> Function 2 : 52 seconds
> >>> Function 3 : 44 seconds
>
> >> So, given that it's a line of code that you'll execute exactly once,
> >> it looks like a toss-up to me.  :-)
>
> > Sorry, English is my second language and is pretty poor - I don't
> > understand you. Can you say that something is wrong in my test code or
> > the results are not true? I tested it 5 times on the Windows machine
> > with killed all not needed other programs and services (Skype, ICQ,
> > MySQL server etc.) The results was be the same 5 times.
>
> I think Brad is saying that, in the worst case, you'll wait an extra 15
> seconds for Function 2 to complete. If you only do this once in your
> life, there is no justification for spending any time optimising it.
>
> Whilst not uninteresting, in the context of this thread (Perl golf?) it
> seems a bit incongruous to be discussing small differences in performance.

That's close.  I actually meant that in the worst case, you'll wait an
extra 0.0000015 seconds.  There's no real case I can imagine when
you're going to request the value of the month and year 10_000_000
times, or even twice.  Okay, if your program runs for months at a
time, I guess you might request it once a day or so.

A millionth of a second here, a millionth of a second there, pretty
soon you're talking real response time.

--
Brad



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

Date: Thu, 28 Jun 2007 19:24:36 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: date parts in one step
Message-Id: <slrnf87rmk.ftu.hjp-usenet2@zeno.hjp.at>

On 2007-06-28 13:18, Brad Baxter <baxter.brad@gmail.com> wrote:
> That's close.  I actually meant that in the worst case, you'll wait an
> extra 0.0000015 seconds.  There's no real case I can imagine when
> you're going to request the value of the month and year 10_000_000
> times, or even twice.

For the current year and month, yes. But you may be reading timestamps
from a logfile or database and calculating year and month for each of
them. Even then I suspect that other operations you do on the data swamp
the differences (But a long time ago I found that the bottleneck in a C
program I had written was either in localtime or mktime (I don't
remember) and I sped it up significantly by reimplementing that
function - so it's certainly possible).

	hp


-- 
   _  | Peter J. Holzer    | I know I'd be respectful of a pirate 
|_|_) | Sysadmin WSR       | with an emu on his shoulder.
| |   | hjp@hjp.at         |
__/   | http://www.hjp.at/ |	-- Sam in "Freefall"


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

Date: Thu, 28 Jun 2007 14:15:10 -0000
From: Justin C <justin.0706@purestblue.com>
Subject: DBIx::Simple, fails with no error (not CGI this time!)
Message-Id: <786a.4683c26e.5ee3c@zem>


My program connects to a database, and is to insert a row into a table. 
It runs with no errors or warnings but the database is not updated.
There is nothing in the Postgresql log either.

Here is the code, it's a small as I can make it:

#!/usr/bin/perl

use warnings ;
use strict ;
use DBIx::Simple ;
use SQL::Abstract ;

my $user = "[user]" ;
my $password = "[passwd]" ;
my $dataSource = DBIx::Simple->connect(
        'dbi:Pg:database=prospects', $user, $password,
        { RaiseError => 1 , AutoCommit => 0 }
) or die DBI::Simple->error ;

my %input = (
    "key" => "4", 
    "contact" => "john", 
    "co_name" => "John's Fluff and Grime Ltd",
    "ad1" => "1 Some Road",
    "town" => "BENJY",
    "p_code" => "BN1",
    "county" => "Middleshire",
    "tel1" => "01234 567234",
);

$dataSource->insert('prospect', \%input);

--- END ---

That last line is taken directly from 
<URL: http://search.cpan.org/~juerd/DBIx-Simple-1.30/lib/DBIx/Simple/Examples.pod#EXAMPLES_WITH_SQL::Abstract>

(except, on the above page they have $db->insert...) 

Any suggestions of where to start looking?

	Justin.

-- 
Justin Catterall                               www.masonsmusic.co.uk
Director                                       T: +44 (0)1424 427562
Masons Music Ltd                               F: +44 (0)1424 434362
                           For full company details see our web site


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

Date: Thu, 28 Jun 2007 10:02:52 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: DBIx::Simple, fails with no error (not CGI this time!)
Message-Id: <1183050172.985662.257880@g4g2000hsf.googlegroups.com>

On Jun 28, 10:15 am, Justin C <justin.0...@purestblue.com> wrote:
> My program connects to a database, and is to insert a row into a table.
> It runs with no errors or warnings but the database is not updated.
> There is nothing in the Postgresql log either.
>
> Here is the code, it's a small as I can make it:
>
> #!/usr/bin/perl
>
> use warnings ;
> use strict ;
> use DBIx::Simple ;
> use SQL::Abstract ;
>
> my $user = "[user]" ;
> my $password = "[passwd]" ;
> my $dataSource = DBIx::Simple->connect(
>         'dbi:Pg:database=prospects', $user, $password,
>         { RaiseError => 1 , AutoCommit => 0 }

You've turned off auto-commit, but never actually comitted your work.
Either turn AutoCommit back on, or explicitly commit your data.  I
recommend a block similar to:

END {
   if ($?) {  # exiting with error
      $dataSource->rollback();
   } else { # success
      $dataSource->commit();
   }
}

Paul Lalli




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

Date: Thu, 28 Jun 2007 09:09:37 -0700
From: "Art VanDelay" <art@xiotek.com>
Subject: Re: FAQ 1.6 What is perl6?
Message-Id: <Y4Rgi.9180$c06.3616@newssvr22.news.prodigy.net>

Tad McClellan wrote:

> Jim Carlock <anonymous@127.0.0.1> wrote:

> > "Tad McClellan" wrote:

> > > Like acceptable spelling.
> > >
> > > If some famous Perl guy would of jsut implemented a
> > > spell-correcting 'bot, then things would of been a lot better
> > > around here...

> > Acceptable grammar? "would have been" or "would of been"?

> Yes, I know. You missed the joke.
>
> I was mocking the troll by repeating his characteristic foibles
> from earlier appearances here.


Unlike someone who attacks without any provocation nor provides any 
proof to back up their arguments?


What you're doing looks to me a lot more like trolling than anything the 
accused has done in this thread. All you've done is sparked an off topic 
tangent thread that's a waste of bandwidth and spool capacity.


-- 
Art 




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

Date: Thu, 28 Jun 2007 10:23:16 -0700
From:  "seven.reeds" <seven.reeds@gmail.com>
Subject: map woes
Message-Id: <1183051396.145639.48880@c77g2000hse.googlegroups.com>

Hi,

I have out-smarted myself.  I have a directory that has various files
inside.  Some are named like:

    <number>.zone

The "<number>" bit is a simple integer so you might have the files:
1.zone, 31.zone, 820.zone, etc

I can open the dir.  I can readdir() to get the filenames, grep() to
get the "\d+\.zone" files but now I want to pull off the numbers, sort
them numericaly highest to lowest and store them for later use.  I
have tried

    my @list =
        sort {$b <=> $a}
        map {s/(\d+)\.news/$1/}
        grep(/\d+\.news/, readdir(NEWSDIR));

The readdir and grep work as I expect.  The result of the map is a
list of "1"s, prolly the count of successful s// matches.  Where am I
messing this up?



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

Date: 28 Jun 2007 17:34:40 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: map woes
Message-Id: <slrnf87s9h.sud.glennj@smeagol.ncf.ca>

At 2007-06-28 01:23PM, "seven.reeds" wrote:
>  I can open the dir.  I can readdir() to get the filenames, grep() to
>  get the "\d+\.zone" files but now I want to pull off the numbers, sort
>  them numericaly highest to lowest and store them for later use.  I
>  have tried
>  
>      my @list =
>          sort {$b <=> $a}
>          map {s/(\d+)\.news/$1/}
>          grep(/\d+\.news/, readdir(NEWSDIR));
>  
>  The readdir and grep work as I expect.  The result of the map is a
>  list of "1"s, prolly the count of successful s// matches.  Where am I
>  messing this up?

You're returning the results of the s/// op, not the matched text.
Change your map block from {s/(\d+)\.news/$1/} to {/(\d+)\./ and $1}

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: Thu, 28 Jun 2007 17:38:08 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: map woes
Message-Id: <4mSgi.14890$xk5.4864@edtnps82>

seven.reeds wrote:
> 
> I have out-smarted myself.  I have a directory that has various files
> inside.  Some are named like:
> 
>     <number>.zone
> 
> The "<number>" bit is a simple integer so you might have the files:
> 1.zone, 31.zone, 820.zone, etc
> 
> I can open the dir.  I can readdir() to get the filenames, grep() to
> get the "\d+\.zone" files but now I want to pull off the numbers, sort
> them numericaly highest to lowest and store them for later use.  I
> have tried
> 
>     my @list =
>         sort {$b <=> $a}
>         map {s/(\d+)\.news/$1/}
>         grep(/\d+\.news/, readdir(NEWSDIR));
> 
> The readdir and grep work as I expect.  The result of the map is a
> list of "1"s, prolly the count of successful s// matches.  Where am I
> messing this up?

The return value of s/// is always true or false (1 or '').  Just use m// 
instead (and you don't really need grep):

     my @list =
         sort { $b <=> $a }
         map  /\A(\d+)\.news\z/,
         readdir NEWSDIR;



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Thu, 28 Jun 2007 10:38:24 -0700
From:  "seven.reeds" <seven.reeds@gmail.com>
Subject: Re: map woes
Message-Id: <1183052304.657700.44540@m36g2000hse.googlegroups.com>

Thanks Glenn,

That was exactly the trick

cheers



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

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 594
**************************************


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