[31268] in Perl-Users-Digest
Perl-Users Digest, Issue: 2513 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 9 18:09:49 2009
Date: Thu, 9 Jul 2009 15:09:16 -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, 9 Jul 2009 Volume: 11 Number: 2513
Today's topics:
Re: FAQ 4.28 How do I change the Nth occurrence of some <brian.d.foy@gmail.com>
Re: FAQ 4.28 How do I change the Nth occurrence of some anno4000@radom.zrz.tu-berlin.de
Re: FAQ 4.28 How do I change the Nth occurrence of some <derykus@gmail.com>
Re: FAQ 4.44 How do I test whether two arrays or hashes <brian.d.foy@gmail.com>
Re: Finding recent files and copy them into another fol <jorg_reyes@hotmail.com>
Re: Finding recent files and copy them into another fol <jimsgibson@gmail.com>
Re: Finding recent files and copy them into another fol <jorg_reyes@hotmail.com>
Re: formatting a number of elsif statements sln@netherlands.com
Re: How to make STDOUT unbuffered, please guide me <ben@morrow.me.uk>
Re: Lets do away with C/C++ and see how long it takes f sln@netherlands.com
Re: Perl Fails To List All The Multiple Matches In The sln@netherlands.com
Re: Perl Fails To List All The Multiple Matches In The sln@netherlands.com
Re: Perl Fails To List All The Multiple Matches In The sln@netherlands.com
Re: Perl scalars as numbers or character strings sln@netherlands.com
Re: Question on a 'perlsub' statement. anno4000@radom.zrz.tu-berlin.de
Re: Question on a 'perlsub' statement. (Tim McDaniel)
Re: Question on a 'perlsub' statement. sln@netherlands.com
Re: Shedding some light on U. Guttman (Tim McDaniel)
Re: To extract file name only from a file <jurgenex@hotmail.com>
Re: To extract file name only from a file <clearguy02@yahoo.com>
Re: To extract file name only from a file <jurgenex@hotmail.com>
Re: To extract file name only from a file <clearguy02@yahoo.com>
Re: To extract file name only from a file <veatchla@yahoo.com>
Re: To extract file name only from a file <clearguy02@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 09 Jul 2009 10:54:05 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.28 How do I change the Nth occurrence of something?
Message-Id: <090720091054054323%brian.d.foy@gmail.com>
In article <anno4000-F9773C.15442506072009@news.cis.dfn.de>, Anno
<anno4000@zrz.tu-berlin.de> wrote:
> In article <5e8eh6-4an.ln1@blue.stonehenge.com>,
> PerlFAQ Server <brian@stonehenge.com> wrote:
>
> > 4.28: How do I change the Nth occurrence of something?
>
> [snip solutions]
>
> Recently I noticed another solution for that:
>
> my $str = '1 whomever 2 whoever 3 whomever' .
> '4 whoever 5 whomever 6 whoever';
> my $n = 5;
> my $re = qr/(whom?)ever/;
>
> $str =~ /$re/g for 1 .. 5; # put pos($str) right past fifth match
> $str =~ s/$re\G/${1}soever/; # replace that one
I don't think this actually works. When I try it with the string '1
whomever' it still makes the change. The problem is that pos() isn't
updated for a failed match, but the for() construct doesn't reconginze
when something failed and it just keeps going. By the time you get to
the last s///, you don't really know if pos() is where it should be.
To fix this, you end up with the code in the answer that checks the
success of the match each time.
------------------------------
Date: 9 Jul 2009 17:48:36 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: FAQ 4.28 How do I change the Nth occurrence of something?
Message-Id: <7bmorjF23v7a0U1@mid.dfncis.de>
brian d foy <brian.d.foy@gmail.com> wrote in comp.lang.perl.misc:
> In article <anno4000-F9773C.15442506072009@news.cis.dfn.de>, Anno
> <anno4000@zrz.tu-berlin.de> wrote:
>
> > In article <5e8eh6-4an.ln1@blue.stonehenge.com>,
> > PerlFAQ Server <brian@stonehenge.com> wrote:
> >
> > > 4.28: How do I change the Nth occurrence of something?
> >
> > [snip solutions]
> >
> > Recently I noticed another solution for that:
> >
> > my $str = '1 whomever 2 whoever 3 whomever' .
> > '4 whoever 5 whomever 6 whoever';
> > my $n = 5;
> > my $re = qr/(whom?)ever/;
> >
> > $str =~ /$re/g for 1 .. 5; # put pos($str) right past fifth match
> > $str =~ s/$re\G/${1}soever/; # replace that one
>
> I don't think this actually works. When I try it with the string '1
> whomever' it still makes the change. The problem is that pos() isn't
> updated for a failed match, but the for() construct doesn't reconginze
> when something failed and it just keeps going. By the time you get to
> the last s///, you don't really know if pos() is where it should be.
Oh, you're right. pos() is undefined (which would be fine) after
the /first/ failed match. Then m//g starts another round.
> To fix this, you end up with the code in the answer that checks the
> success of the match each time.
Not quite. Just stop the loop after the first failure, when
pos() is fine:
# put pos($str) right past $n-th match
# leave undef if there aren't $n matches
$str =~ /$re/g or last for 1 .. $n;
# replace that one
$str =~ s/$re\G/${1}SOever/;
That would fix it, but the purpose of "...or last" is obscure. I like
the bogus solution better, it's much clearer :)
Anno
------------------------------
Date: Thu, 9 Jul 2009 13:11:30 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: FAQ 4.28 How do I change the Nth occurrence of something?
Message-Id: <937440cb-1d0a-4d4d-9496-f99769d2b3ed@x5g2000prf.googlegroups.com>
On Jul 9, 10:48=A0am, anno4...@radom.zrz.tu-berlin.de wrote:
> brian d foy =A0<brian.d....@gmail.com> wrote in comp.lang.perl.misc:
>
>
>
> > In article <anno4000-F9773C.15442506072...@news.cis.dfn.de>, Anno
> > <anno4...@zrz.tu-berlin.de> wrote:
>
> > > In article <5e8eh6-4an....@blue.stonehenge.com>,
> > > =A0PerlFAQ Server <br...@stonehenge.com> wrote:
>
> > > > 4.28: How do I change the Nth occurrence of something?
>
> > > [snip solutions]
>
> > > Recently I noticed another solution for that:
>
> > > =A0 =A0 my $str =3D '1 whomever 2 whoever 3 whomever' .
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 '4 whoever 5 whomever 6 whoever';
> > > =A0 =A0 my $n =3D 5;
> > > =A0 =A0 my $re =3D qr/(whom?)ever/;
>
> > > =A0 =A0 $str =3D~ /$re/g for 1 .. 5; =A0 =A0# put pos($str) right pas=
t fifth match
> > > =A0 =A0 $str =3D~ s/$re\G/${1}soever/; =A0# replace that one
>
> > I don't think this actually works. =A0When I try it with the string '1
> > whomever' it still makes the change. The problem is that pos() isn't
> > updated for a failed match, but the for() construct doesn't reconginze
> > when something failed and it just keeps going. By the time you get to
> > the last s///, you don't really know if pos() is where it should be.
>
> Oh, you're right. =A0pos() is undefined (which would be fine) after
> the /first/ failed match. =A0Then m//g starts another round.
>
> > To fix this, you end up with the code in the answer that checks the
> > success of the match each time.
>
> Not quite. =A0Just stop the loop after the first failure, when
> pos() is fine:
>
> =A0 =A0 # put pos($str) right past $n-th match
> =A0 =A0 # leave undef if there aren't $n matches
> =A0 =A0 $str =3D~ /$re/g or last for 1 .. $n;
>
> =A0 =A0 # replace that one
> =A0 =A0 $str =3D~ s/$re\G/${1}SOever/;
>
> That would fix it, but the purpose of "...or last" is obscure. =A0I like
> the bogus solution better, it's much clearer :)
Or, use /gc and stop one short of the match count:
my $n =3D 5;
my $re =3D qr/(whom?)ever/;
$str =3D~ /$re/gc} for 1 .. $n-1; # position at match-1
$str =3D~ s/\G(.*?)$re/$1${2}soever/ # replace next if any
--
Charles DeRykus
------------------------------
Date: Thu, 09 Jul 2009 10:44:43 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.44 How do I test whether two arrays or hashes are equal?
Message-Id: <090720091044430589%brian.d.foy@gmail.com>
In article <2v8555plbhi96cssale5kpiv79v6ib0247@4ax.com>,
<sln@netherlands.com> wrote:
> >4.44: How do I test whether two arrays or hashes are equal?
> >
> > With Perl 5.10 and later, the smart match operator can give you the
> > answer with the least amount of work:
> >
> > use 5.010;
> >
> > if( @array1 ~~ @array2 )
> > {
> > say "The arrays are the same";
> > }
> >
> > if( %hash1 ~~ %hash2 ) # doesn't check values!
> > {
> > say "The hash keys are the same";
> > }
> >
> Well, this is dumb, where's the less than 5.10 ~~ operator?
> Where's the !~~ operator? What version?
There is no smart match operator before 5.10. You have to use the
techniques from the rest of the answer.
------------------------------
Date: Thu, 9 Jul 2009 12:11:59 -0700 (PDT)
From: Jorge Reyes <jorg_reyes@hotmail.com>
Subject: Re: Finding recent files and copy them into another folder
Message-Id: <6f833c03-921f-485c-9587-67df065f8323@k19g2000yqn.googlegroups.com>
On 9 jul, 00:16, "C.DeRykus" <dery...@gmail.com> wrote:
> On Jul 8, 5:14=A0pm, Jorge Reyes <jorg_re...@hotmail.com> wrote:
>
>
>
>
>
> > Hi everyone,
>
> > I have this issue which is killing me, this is the scenario
>
> > if i make =A0 ls -l =A0 =A0 i get this:
> > -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 18:47 file=
1.pl
> > -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:07 file=
2.pl
> > -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:10 file=
3.pl
>
> > now what i need is only the files were accessed >=3D 19:00 =A0i.e.
> > -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:07 file=
2.pl
> > -rw-r--r-- =A0 1 netrac =A0 netrac =A0 =A0 =A02928 jul =A0 8 19:10 file=
3.pl
>
> > i found this example which create a rule to find only files (and not
> > directories or other things) that have been accessed at least 14 days
> > ago
>
> > use File::Find::Rule;
> > my $path =3D "/data";
> > my @results =3D File::Find::Rule->file->ctime('>14')->in($path);
> > foreach my $i (@results) {
> > =A0 =A0 =A0 =A0 print "$i\n";
>
> > }
>
> > Question is, instead 14 days ago, a specific time i.e. >=3D current
> > system date ????
>
> [untested]
>
> use File::Find::Rule;
> use Time::Local;
>
> my $target =3D timelocal( 0, 0, 0, 19, 6, 2009 );
> my @results =3D File::Find::Rule
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ->file
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ->exec(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sub{ (stat($_))[10] - $target < 0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0? $_ =A0 : ''
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} =A0)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ->in($path);
>
> --
> Charles DeRykus
Hi everyone,
Thanks for your response C.DeRykus but i have a lot of questions,
first of all the target of this script is parse the files stored in a
specific folder and then copy into another folder, these files are
constantly emerging and the script should detect them, so, my logic
is:
First time i run the script, it takes the files from this moment
Parse the files one by one
At the end of each parse, copy the file to another folder
Save the max ctime of all the parsed files
Sleep 10 minutes and then wake up and look up for new files (taking
the saved datetime as started point)
If there are new files then repit the proccess, else Sleep another 10
minutes.
Am I greatly complicated? please give me some ideas :(
Thank you so much all of you!!
------------------------------
Date: Thu, 09 Jul 2009 13:16:11 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Finding recent files and copy them into another folder
Message-Id: <090720091316118997%jimsgibson@gmail.com>
In article
<6f833c03-921f-485c-9587-67df065f8323@k19g2000yqn.googlegroups.com>,
Jorge Reyes <jorg_reyes@hotmail.com> wrote:
> Hi everyone,
>
> Thanks for your response C.DeRykus but i have a lot of questions,
>
> first of all the target of this script is parse the files stored in a
> specific folder and then copy into another folder, these files are
> constantly emerging and the script should detect them, so, my logic
> is:
>
> First time i run the script, it takes the files from this moment
> Parse the files one by one
> At the end of each parse, copy the file to another folder
> Save the max ctime of all the parsed files
> Sleep 10 minutes and then wake up and look up for new files (taking
> the saved datetime as started point)
> If there are new files then repit the proccess, else Sleep another 10
> minutes.
>
> Am I greatly complicated? please give me some ideas :(
How long does the copy exist? If you parse the file, then copy it, you
can use the presence of the copy to indicate that the file has been
parsed. Otherwise, you may encounter some race condition in which you
miss files because they appear after your check, but with a ctime
earlier than your max ctime of the files you are processing.
You could also move the original file to some other directory after it
has been successfully processed, if that does not interfere with some
other function.
--
Jim Gibson
------------------------------
Date: Thu, 9 Jul 2009 14:47:43 -0700 (PDT)
From: Jorge Reyes <jorg_reyes@hotmail.com>
Subject: Re: Finding recent files and copy them into another folder
Message-Id: <b136b212-ff81-42d7-abaf-8d2947c24841@a7g2000yqk.googlegroups.com>
On 9 jul, 15:16, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <6f833c03-921f-485c-9587-67df065f8...@k19g2000yqn.googlegroups.com>,
>
>
>
>
>
> Jorge Reyes <jorg_re...@hotmail.com> wrote:
> > Hi everyone,
>
> > Thanks for your response C.DeRykus but i have a lot of questions,
>
> > first of all the target of this script is parse the files stored in a
> > specific folder and then copy into another folder, these files are
> > constantly emerging and the script should detect them, so, my logic
> > is:
>
> > First time i run the script, it takes the files from this moment
> > Parse the files one by one
> > At the end of each parse, copy the file to another folder
> > Save the max ctime of all the parsed files
> > Sleep 10 minutes and then wake up and look up for new files (taking
> > the saved datetime as started point)
> > If there are new files then repit the proccess, else Sleep another 10
> > minutes.
>
> > Am I greatly complicated? please give me some ideas :(
>
> How long does the copy exist? If you parse the file, then copy it, you
> can use the presence of the copy to indicate that the file has been
> parsed. Otherwise, you may encounter some race condition in which you
> miss files because they appear after your check, but with a ctime
> earlier than your max ctime of the files you are processing.
>
> You could also move the original file to some other directory after it
> has been successfully processed, if that does not interfere with some
> other function.
>
> --
> Jim Gibson
Hi thank you Jim,
Well, in fact that could be an alternative i mean, the idea will be:
1. Run the script and copy all the files which last created time is
the last 10 minutes.
2. Change dir to that "work folder" and parse the files one by one (at
this step, it would be very useful sort the files by ctime)
3. If the files were sorted, then the last parsed file contain the the
max ctime, so save it into $lastparsetime.
4. Sleep 10 minutes.
5. Wake up and look up for new files (taking the $lastparsetime as
started point), if exists then repit the proccess, else Sleep another
10 minutes.
This is what i have, but this is not doing the above, any help
please????
use strict;
use File::Find::Rule;
use Time::Local;
my $DIR = "/home/netrac/BSMPERL";
my $DIRW = "/raw_data/COMPLETED/BSM";
my $DIRBIN = "$DIR/bin";
my $DIRLOG = "$DIR/log";
my $DIRDAT = "$DIR/dat";
my $LOGFILE = "$DIRLOG/BSMLog.log";
my $target = timelocal( 0, 0, 0, 8, 7, 2009 );
my @results = File::Find::Rule
->file
->name('MCBTSSubsystem-*.gz')
->exec( sub{ (stat($_))[10] - $target > 0 ? $_ :
'' } )
->in($DIRW);
foreach my $i (@results) {
print "$i\n";
}
------------------------------
Date: Thu, 09 Jul 2009 14:39:54 -0700
From: sln@netherlands.com
Subject: Re: formatting a number of elsif statements
Message-Id: <evnc551vnn2afljonl8gia9pqdpcand5q7@4ax.com>
On Thu, 9 Jul 2009 07:18:09 +0200, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>On Mon, 06 Jul 2009 13:32:51 -0700, sln wrote:
>
>>>Another reason is that it can often be implemented using a branch table.
>>>
>> [snip]
>>>
>>>M4
>>
>> I'm sorry, I missed that branch table instruction in the op code list
>> (rst?). Perhaps you should dissasemble your assembler.
>
>It's called an indirect jump. Sorry, but you really should take some
>education here, these are rather basic concepts.
>
>M4
I don't know if there is an indirect jump op code. The accumulator may contain
an address, and there may be a jump to where it points. Any kind of indirection
involves a 2-step loading of a fixed address into a register, getting its contents
then loading it into another register (with a possible addition).
Jumping to a fixed location is more than four times quicker, as is the case of
if/then/else.
I'm sorry, machine cycles (if there is a relative jump op) don't change. The math
is still the same.
Back in the days of 'resident' dos programs it made a difference, today it still
makes a difference.
Surely, real-time.
-sln
------------------------------
Date: Thu, 9 Jul 2009 16:08:52 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to make STDOUT unbuffered, please guide me
Message-Id: <4pdhi6-q113.ln1@osiris.mauzo.dyndns.org>
Quoth Josef Moellers <josef.moellers@ts.fujitsu.com>:
> sahana H V wrote:
> >
> > Can i make stdout associated with my own file handle as unbuffered ?
> > If so can you please tell me how to do it?
> >
> > What i am trying to do is:
> >
> > open (HVS, "/<command> <cmnd_args> 2>&1 |"); <==
> > at this point of time i need stdout to be unbuffered .so that command output
> > should be logged to HVS in unbuffered fashion.
>
> You can't, unless you have control over the command.
>
> It's the binary of the command (more precise: the stdio library linked
> to the command) which does the buffering and if stdout is not connected
> to a terminal (and a pipe is *not* a terminal), it will buffer its output.
You could try using IO::Run's ">pty>" syntax, or using a pty yourself.
Ben
------------------------------
Date: Thu, 09 Jul 2009 14:53:22 -0700
From: sln@netherlands.com
Subject: Re: Lets do away with C/C++ and see how long it takes for the world economy to collapse ~ 1 nano second
Message-Id: <flpc55lu358pn03rsess2d26p6oguke94a@4ax.com>
On Mon, 06 Jul 2009 22:22:38 -0700, Jürgen Exner <jurgenex@hotmail.com> wrote:
>Tad J McClellan <tadmc@seesig.invalid> wrote:
>>sln@netherlands.com <sln@netherlands.com> wrote:
>>> I'm just fed up with all the bullshit on this site
>>
>>This is not a "site".
>
>How would we know?
>
>As usual he didn't specify what "site" he is talking about. We may have
>some idea but for all we know he could be ranting about a Chinese
>spammers web site or some bad Perl online tutorial (although I have to
>admit, chances for that are close to epsilon).
>
>jue
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Was that an insult from tweedle dee?
-sln
------------------------------
Date: Thu, 09 Jul 2009 13:51:48 -0700
From: sln@netherlands.com
Subject: Re: Perl Fails To List All The Multiple Matches In The Same Line?
Message-Id: <8tlc55tkd42i5n0ciu8u9ue35prdubbf37@4ax.com>
On Wed, 08 Jul 2009 01:27:10 -0700, "John W. Krahn" <someone@example.com> wrote:
>Cibalo wrote:
>>
<snip>
>> Even with the global modifier, the above perl script lists only the
>> first pattern match with multiple matches in the same line. But I can
>> make it worked with grep as listed above.
>
>The problem is that even with the global option the pattern is evaluated
>in scalar context and so will only match once. You need to either match
>in list context:
>
>$ echo "zip1 10036; zip2 48226; zip3 94128
>zip4 V8Y 1L1; zip5 400069
>zip6
>zip7 12345
>" | perl -lne'print "$.: $_" for /\b[0-9]{5}\b/g'
^^^^^^^^^^^^^^^^^^^
Carefull, someone might accuse you of obfuscation.
while (<DATA>)
{
print;
@_ = $_ =~ /\b[0-9]{5}\b/g;
for (@_)
{
print "$.: $_\n";
}
}
-sln
------------------------------
Date: Thu, 09 Jul 2009 14:09:13 -0700
From: sln@netherlands.com
Subject: Re: Perl Fails To List All The Multiple Matches In The Same Line?
Message-Id: <gdmc55h4biemdlavdm1fv5nq975g1cp0vs@4ax.com>
On Wed, 08 Jul 2009 01:27:10 -0700, "John W. Krahn" <someone@example.com> wrote:
>Cibalo wrote:
>>
>> I would like to list all the 5-digit zip codes in my database, of
>> which a line may contain more than one zip codes. Then, I create a
>> test database, testdb, for testing as follows.
>>
>> # echo -e 'zip1 10036; zip2 48226; zip3 94128\nzip4 V8Y 1L1; zip5
>> 400069\nzip6 \nzip7 12345' > testdb
>> # cat testdb
>> zip1 10036; zip2 48226; zip3 94128
>> zip4 V8Y 1L1; zip5 400069
>> zip6
>> zip7 12345
>> # perl -wnl -e '/\b[0-9]{5}\b/g and print "$.: $&";' testdb
>> 1: 10036
>> 4: 12345
>> # grep -now -e '[0-9]\{5\}' testdb
>> 1:10036
>> 48226
>> 94128
>> 4:12345
>> #
>>
>> Even with the global modifier, the above perl script lists only the
>> first pattern match with multiple matches in the same line. But I can
>> make it worked with grep as listed above.
>
>The problem is that even with the global option the pattern is evaluated
>in scalar context and so will only match once. You need to either match
>in list context:
>
>$ echo "zip1 10036; zip2 48226; zip3 94128
>zip4 V8Y 1L1; zip5 400069
>zip6
>zip7 12345
>" | perl -lne'print "$.: $_" for /\b[0-9]{5}\b/g'
>1: 10036
>1: 48226
>1: 94128
>4: 12345
>
>
>Or match all patterns in scalar context:
>
>$ echo "zip1 10036; zip2 48226; zip3 94128
>zip4 V8Y 1L1; zip5 400069
>zip6
>zip7 12345
>" | perl -lne'print "$.: $1" while /\b([0-9]{5})\b/g'
^^^^^^^^^^^^^^^^^^^^^^^
>1: 10036
>1: 48226
>1: 94128
>4: 12345
>
>
>
>John
I always enjoy (and marvel at) seeing Unix 1 liner shell
compositions here. Seems so at ease and natural. I just got Windyo'z.
When I cut and paste these 1 liners (even though my shell does 'echo')
each line is treated as a new command, even when I batch it.
Unfortunately, the {'"} syntax is also different under Windows (and I
have XP, the great).
Why can't windows do unix?
Oh well, I have to settle for the 'jist' and test using a pl file.
This last works as expected, the first (list context) is slightly obfuscated,
or would be to the OP, who never got past the /g switch meaning.
Btw, nice explanation John.
while (<DATA>)
{
while (/\b([0-9]{5})\b/g)
{
print "$.: $1\n";
}
}
-sln
------------------------------
Date: Thu, 09 Jul 2009 14:18:22 -0700
From: sln@netherlands.com
Subject: Re: Perl Fails To List All The Multiple Matches In The Same Line?
Message-Id: <1fnc55dmmgkqrk81uvvonkpbp368n4aqaa@4ax.com>
On Thu, 09 Jul 2009 13:51:48 -0700, sln@netherlands.com wrote:
>On Wed, 08 Jul 2009 01:27:10 -0700, "John W. Krahn" <someone@example.com> wrote:
>
>>Cibalo wrote:
>>>
><snip>
>>> Even with the global modifier, the above perl script lists only the
>>> first pattern match with multiple matches in the same line. But I can
>>> make it worked with grep as listed above.
>>
>>The problem is that even with the global option the pattern is evaluated
>>in scalar context and so will only match once. You need to either match
>>in list context:
>>
>>$ echo "zip1 10036; zip2 48226; zip3 94128
>>zip4 V8Y 1L1; zip5 400069
>>zip6
>>zip7 12345
>>" | perl -lne'print "$.: $_" for /\b[0-9]{5}\b/g'
> ^^^^^^^^^^^^^^^^^^^
>Carefull, someone might accuse you of obfuscation.
>
>while (<DATA>)
>{
> print;
> @_ = $_ =~ /\b[0-9]{5}\b/g;
> for (@_)
> {
> print "$.: $_\n";
> }
>}
>
>-sln
Funny how
for /\b[0-9]{5}\b/g
works, but this
@_ = $_ =~ /\b[0-9]{5}\b/g;
for ()
doesen't.
As though the shortcut's got shorted.
-sln
------------------------------
Date: Thu, 09 Jul 2009 15:07:15 -0700
From: sln@netherlands.com
Subject: Re: Perl scalars as numbers or character strings
Message-Id: <oupc55lumcaj2i92g7d361pe0vgjdq5faq@4ax.com>
On Tue, 07 Jul 2009 14:08:25 -0700, Keith Thompson <kst-u@mib.org> wrote:
>sln@netherlands.com writes:
>> On Mon, 06 Jul 2009 18:26:21 -0700, Keith Thompson <kst-u@mib.org> wrote:
>>>sln@netherlands.com writes:
>>>> On Mon, 06 Jul 2009 18:16:11 -0400, Uri Guttman
>>>> <uri@stemsystems.com> wrote:
>>>[...]
>>>>>then you have an aversion to most popular languages today. c is still
>>>>>used and is useful but it isn't good for dynamic data which is what web
>>>>>apps typically need.
>>>>
>>>> WTF is a Web App, lol !!!!
>>>
>>><http://lmgtfy.com/?q=web+app>
>>>
>>>[...]
>>
>> You know i won't explore any links anybody types here.
>> Wanna know why? Cause some jack-off like you points to a page that
>> will load my machine with a virus.
>
>Ok, fine. If you really want an answer to your question, go to
>www.google.com and type "web app" into the search box, or do the
>research in any other manner you like. And your accusation is
>unfounded, untrue, and stupid. (I don't deny that some people would
>post malicious links; I deny that I would do so or have done so,
>and that you have any basis for assuming that I would or did.
>
>> In lieu of a voice, I suggest you recant to yourself just exactly what
>> C/C++/api's writtine on them (f***in all of them) are f***ing good for
^^^ ^^^
>> you moron.
>
>Quoted text edited for content.
>
>Plonk. (Since you probably won't look that up, it means I'm adding
>you to my killfile and am unlikely to see anything you post in the
>future.)
Your a cartoon character from Toon Town. The more plonks the better,
as if silly little people like you who post on usenet from censured html
sites, who post nefarious one-line html links as a reply, mean jack shit to me.
I'm going to say it again. Everything WEB/ANYTHING api is written in assembly/C/C++.
Stop the bullshit and get your head out of your ass!!
-sln
------------------------------
Date: 9 Jul 2009 18:01:08 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Question on a 'perlsub' statement.
Message-Id: <7bmpj4F23v7a0U2@mid.dfncis.de>
C.DeRykus <derykus@gmail.com> wrote in comp.lang.perl.misc:
> On Jul 8, 4:42 pm, pac...@kosh.dhis.org (Alan Curry) wrote:
>
> ...
>
> > All right, by now we all know now that
> > ($x) = something_returning_a_list();
> > my ($x) = something_returning_a_list();
> > both discard all but the first element of the generated list. New questions:
> > ...
> > If you saw a statement of that form in perl code, withou
> > If it can be agreed that the slightly more verbose forms
> > $x = (something_returning_a_list())[0];
> > my $x = (something_returning_a_list())[0];
> > are easier to read, might we get a warning for the "too subtle" form?
>
> I tend to agree but IMO the less cluttered
>
> ( my $x, () ) = something_returning_a_list();
>
> is an improvement with the empty list () clearly
> signaling the throw-away's.
Ah, but that only looks like a throwaway, but isn't one.
(my $x, (), my $y) = qw(one two three);
say "$x $y"; # "one two"
So it doesn't convey the intention very clearly.
Anno
------------------------------
Date: Thu, 9 Jul 2009 18:42:30 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Question on a 'perlsub' statement.
Message-Id: <h35dmm$ms0$1@reader1.panix.com>
In article <681c5593h77enm8nuqdn8pe5jckrks1t1f@4ax.com>,
Jürgen Exner <jurgenex@hotmail.com> wrote:
>Tad J McClellan <tadmc@seesig.invalid> wrote:
>>I have a subroutine that returns a 2-element list: a user ID, and the
>>age of their session.
>>
>>When I don't intend to use the age of the session
>> my($user_id) = somefunc();
>>_IS_ a favor to future readers. It tells them that I don't intend
>>to use the age.
>
>Or that the programmer isn't aware/forgot that there are more return
>values.
> (my $user_id, undef) = somefunc();
>would be even more explicit.
I just checked
perl -e 'my($a, undef) = (2, 3); print $a, "\n"'
under 5.005, 5.6.1, 5.8.8, and 5.10, and it prints "2" without a
warning or error in each of them. Even
perl -e 'my (undef) = 2;'
works. (The versions without "my" worked the same as with.)
I think I'll be more likely henceforth to put undef on the left-hand
side just to make it clear that I know that it's throwing away values.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Thu, 09 Jul 2009 14:50:34 -0700
From: sln@netherlands.com
Subject: Re: Question on a 'perlsub' statement.
Message-Id: <5cpc55hdpka6bdqfknnkeuqqeqc0r15bsc@4ax.com>
On 9 Jul 2009 18:01:08 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>C.DeRykus <derykus@gmail.com> wrote in comp.lang.perl.misc:
>> On Jul 8, 4:42 pm, pac...@kosh.dhis.org (Alan Curry) wrote:
>>
>> ...
>>
>> > All right, by now we all know now that
>> > ($x) = something_returning_a_list();
>> > my ($x) = something_returning_a_list();
>> > both discard all but the first element of the generated list. New questions:
>> > ...
>> > If you saw a statement of that form in perl code, withou
>> > If it can be agreed that the slightly more verbose forms
>> > $x = (something_returning_a_list())[0];
>> > my $x = (something_returning_a_list())[0];
>> > are easier to read, might we get a warning for the "too subtle" form?
>>
>> I tend to agree but IMO the less cluttered
>>
>> ( my $x, () ) = something_returning_a_list();
>>
>> is an improvement with the empty list () clearly
>> signaling the throw-away's.
>
>Ah, but that only looks like a throwaway, but isn't one.
>
> (my $x, (), my $y) = qw(one two three);
> say "$x $y"; # "one two"
>
>So it doesn't convey the intention very clearly.
>
>Anno
Or, more explanitory:
my $result = my ($aa,$bb) = (1,2,3,4,5,6,7);
print $result,"\n";
-sln
------------------------------
Date: Thu, 9 Jul 2009 18:48:19 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Shedding some light on U. Guttman
Message-Id: <h35e1j$ms0$2@reader1.panix.com>
In article <5bta55han89k3dn7r5b9eftntkp8jtdujf@4ax.com>,
Jürgen Exner <jurgenex@hotmail.com> wrote:
>New users to this group should also be aware that neither Ralph Malph
>nor Jon Kim have ever posted to this NG before. Their only(!)
>contribution ever is badmouthing a long-standing, respected member of
>CLPM.
>
>I'd call them drive-by posters
The usual Internet jargon for at least the second poster is
<http://www.catb.org/jargon/html/S/sock-puppet.html>:
sock puppet: n.
[Usenet: from the act of placing a sock over your hand and talking
to it and pretending it's talking back] In Usenet parlance, a
_pseudo_ through which the puppeteer posts follow-ups to their own
original message to give the appearance that a number of people
support the views held in the original message. See also
_astroturfing_, _tentacle_.
If there was an original person dissing Uri, then both Jon Kim and
Ralph Malph would be sock puppets, of course.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Thu, 09 Jul 2009 08:23:02 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: To extract file name only from a file
Message-Id: <dg2c55drgkf2met8cb1950g4106u0nkh8f@4ax.com>
Rider <clearguy02@yahoo.com> wrote:
>I have this file, inut.txt (listed below). each line in the file has
>more than 10 fields, but I am just listing a sample format here.
>
>I need to print out only the filenames that are ending with .txt in
>the output..
>
>The output should be:
>===============
>unixFile1.txt
>unixFile2.txt
This looks like a standard CSV format, and you want the third column. So
I would use Text::CSV and grab the third element from each row.
If you insist on reinventing the wheel then at least for the sample data
you have shown you can grab the third element after split()ing each line
at the comma.
jue
------------------------------
Date: Thu, 9 Jul 2009 08:50:33 -0700 (PDT)
From: Rider <clearguy02@yahoo.com>
Subject: Re: To extract file name only from a file
Message-Id: <87b2c0fb-6c0e-4a3f-9984-6d3dc1d8e2d7@2g2000prl.googlegroups.com>
On Jul 9, 8:06=A0am, Josef Moellers <josef.moell...@ts.fujitsu.com>
wrote:
> Rider wrote:
> > Hi experts,
>
> > I have this file, inut.txt (listed below). each line in the file has
> > more than 10 fields, but I am just listing a sample format here.
>
> > I need to print out only the filenames that are ending with .txt in
> > the output..
>
> > The output should be:
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > unixFile1.txt
> > unixFile2.txt
> > unixFile3.txt
> > ...
> > ..
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > I am looking out for a shorter form of a reg exp to extract only the
> > file names in to the output here. I do the basic perl coding on an
> > occasional basis, but don't know the right reg exp to do it.
>
> > Thanks in advance,
> > J
>
> > Here is the input file.
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > 1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
> > 2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
> > 3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
> > .....
> > ....
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> $f1 =3D (split(/\//, (split(/,\s+/, $line))[2]))[-1];
> print "$f1\n" if $f1 =3D~ /\.txt$/;
>
> --
> These are my personal views and not those of Fujitsu Technology Solutions=
!
> Josef M=F6llers (Pinguinpfleger bei FTS)
> =A0 =A0 =A0 =A0 If failure had no penalty success would not be a prize (T=
. =A0Pratchett)
> Company Details:http://de.ts.fujitsu.com/imprint.html
Thanks Josef,
But I am looking out for a one-liner of just grabbing the only file
name that ends with .txt from each line with no need of using split
function. I am sure that that I saw that kind of reg expression
before, but I can not recall now.
------------------------------
Date: Thu, 09 Jul 2009 09:07:02 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: To extract file name only from a file
Message-Id: <7s4c55dhmsbiu5r9qnuj7rfrjtj6b5fuls@4ax.com>
Rider <clearguy02@yahoo.com> wrote:
>> Rider wrote:
>> > I need to print out only the filenames that are ending with .txt in
>> > the output..
>>
>> > The output should be:
>> > ===============
>> > unixFile1.txt
>> > unixFile2.txt
>> > unixFile3.txt
>> > ...
>> > 1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
>> > 2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
>> > 3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
>> > .....
>But I am looking out for a one-liner of just grabbing the only file
>name that ends with .txt from each line with no need of using split
>function. I am sure that that I saw that kind of reg expression
>before, but I can not recall now.
Unless this is some academic excercise why do you want to do it the hard
way?
It is the easy way and the most robust way to use Text::CSV, grab the
third item, and then use File::Basename to extract the file name.
Or actually in your case you could also use
substr($line, 16, 13) #might be off by one somewhere
because the filename starts at character 16 and is 13 characters long.
Oh, you mean that's just your sample data and the actual data might vary
in lenght? Well, to bad, because your actual data may also vary in such
a way to make a regexp fail. That is exactly why using Text::CSV and
File::Basename are more robust and spare you from patching your
hand-rolled code over and over again whenever you encounter some
unforeseen data.
jue
------------------------------
Date: Thu, 9 Jul 2009 09:32:10 -0700 (PDT)
From: Rider <clearguy02@yahoo.com>
Subject: Re: To extract file name only from a file
Message-Id: <ec437cb9-4d87-468d-8b4e-d29b47797ced@c1g2000yqi.googlegroups.com>
On Jul 9, 9:07=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> Rider <cleargu...@yahoo.com> wrote:
> >> Rider wrote:
> >> > I need to print out only the filenames that are ending with .txt in
> >> > the output..
>
> >> > The output should be:
> >> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> > unixFile1.txt
> >> > unixFile2.txt
> >> > unixFile3.txt
> >> > ...
> >> > 1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
> >> > 2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
> >> > 3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
> >> > .....
> >But I am looking out for a one-liner of just grabbing the only file
> >name that ends with .txt from each line with no need of using split
> >function. I am sure that that I saw that kind of reg expression
> >before, but I can not recall now.
>
> Unless this is some academic excercise why do you want to do it the hard
> way?
> It is the easy way and the most robust way to use Text::CSV, grab the
> third item, and then use File::Basename to extract the file name.
>
> Or actually in your case you could also use
> =A0 =A0 =A0 =A0 substr($line, 16, 13) #might be off by one somewhere
> because the filename starts at character 16 and is 13 characters long.
>
> Oh, you mean that's just your sample data and the actual data might vary
> in lenght? Well, to bad, because your actual data may also vary in such
> a way to make a regexp fail. That is exactly why using Text::CSV and
> File::Basename are more robust and spare you from patching your
> hand-rolled code over and over again whenever you encounter some
> unforeseen data.
>
> jue
It is not a CSV file.. it is a PHP file with a lot of comments in the
middle of the file as well.
So I am looking out for a reg exp for just gets me only the file name
that is ending with .txt (this file might have a space in the middle..
example: user input.txt, instead of userinput.txt).
------------------------------
Date: Thu, 09 Jul 2009 11:53:29 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: To extract file name only from a file
Message-Id: <Go2dnZMS848XvcvXnZ2dnUVZ_rKdnZ2d@supernews.com>
Rider wrote:
> On Jul 9, 8:06 am, Josef Moellers <josef.moell...@ts.fujitsu.com>
> wrote:
>> Rider wrote:
>>> Hi experts,
>>> I have this file, inut.txt (listed below). each line in the file has
>>> more than 10 fields, but I am just listing a sample format here.
>>> I need to print out only the filenames that are ending with .txt in
>>> the output..
>>> The output should be:
>>> ===============
>>> unixFile1.txt
>>> unixFile2.txt
>>> unixFile3.txt
>>> ...
>>> ..
>>> ===============
>>> I am looking out for a shorter form of a reg exp to extract only the
>>> file names in to the output here. I do the basic perl coding on an
>>> occasional basis, but don't know the right reg exp to do it.
>>> Thanks in advance,
>>> J
>>> Here is the input file.
>>> ===================
>>> 1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
>>> 2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
>>> 3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
>>> .....
>>> ....
>>> ===================
>> $f1 = (split(/\//, (split(/,\s+/, $line))[2]))[-1];
>> print "$f1\n" if $f1 =~ /\.txt$/;
>>
>> --
>> These are my personal views and not those of Fujitsu Technology Solutions!
>> Josef Möllers (Pinguinpfleger bei FTS)
>> If failure had no penalty success would not be a prize (T. Pratchett)
>> Company Details:http://de.ts.fujitsu.com/imprint.html
>
> Thanks Josef,
>
> But I am looking out for a one-liner of just grabbing the only file
> name that ends with .txt from each line with no need of using split
> function. I am sure that that I saw that kind of reg expression
> before, but I can not recall now.
perl -nle 'print $1 if (/.+\/(.+\.txt)/)' rider.txt
where rider.txt is your input file.
D:\Perl\source\1>perl -nle "print $1 if (/.+\/(.+\.txt)/)" rider.txt
unixFile1.txt
unixFile2.txt
unixFile3.txt
--
Len
------------------------------
Date: Thu, 9 Jul 2009 10:01:26 -0700 (PDT)
From: Rider <clearguy02@yahoo.com>
Subject: Re: To extract file name only from a file
Message-Id: <0cc8d496-8e57-4e55-a365-73c836bcbc85@d4g2000prc.googlegroups.com>
On Jul 9, 9:53=A0am, l v <veatc...@yahoo.com> wrote:
> Rider wrote:
> > On Jul 9, 8:06 am, Josef Moellers <josef.moell...@ts.fujitsu.com>
> > wrote:
> >> Rider wrote:
> >>> Hi experts,
> >>> I have this file, inut.txt (listed below). each line in the file has
> >>> more than 10 fields, but I am just listing a sample format here.
> >>> I need to print out only the filenames that are ending with .txt in
> >>> the output..
> >>> The output should be:
> >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >>> unixFile1.txt
> >>> unixFile2.txt
> >>> unixFile3.txt
> >>> ...
> >>> ..
> >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >>> I am looking out for a shorter form of a reg exp to extract only the
> >>> file names in to the output here. I do the basic perl coding on an
> >>> occasional basis, but don't know the right reg exp to do it.
> >>> Thanks in advance,
> >>> J
> >>> Here is the input file.
> >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >>> 1, bob, usr/tst/unixFile1.txt, boston, text1, text2, text3
> >>> 2, bob, usr/tst/unixFile2.txt, boston, text1, text2, text3
> >>> 3, bob, usr/tst/unixFile3.txt, boston, text1, text2, text3
> >>> .....
> >>> ....
> >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >> $f1 =3D (split(/\//, (split(/,\s+/, $line))[2]))[-1];
> >> print "$f1\n" if $f1 =3D~ /\.txt$/;
>
> >> --
> >> These are my personal views and not those of Fujitsu Technology Soluti=
ons!
> >> Josef M=F6llers (Pinguinpfleger bei FTS)
> >> =A0 =A0 =A0 =A0 If failure had no penalty success would not be a prize=
(T. =A0Pratchett)
> >> Company Details:http://de.ts.fujitsu.com/imprint.html
>
> > Thanks Josef,
>
> > But I am looking out for a one-liner of just grabbing the only file
> > name that ends with .txt from each line with no need of using split
> > function. I am sure that that I saw that kind of reg expression
> > before, but I can not recall now.
>
> perl -nle 'print $1 if (/.+\/(.+\.txt)/)' rider.txt
>
> where rider.txt is your input file.
>
> D:\Perl\source\1>perl -nle "print $1 if (/.+\/(.+\.txt)/)" rider.txt
> unixFile1.txt
> unixFile2.txt
> unixFile3.txt
>
> --
>
> Len
Awesome Len..
Thanks a bunch.. this serves my purpose. Though I did not run, I can
see that it would work.
------------------------------
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 2513
***************************************