[23487] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5700 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 23 06:06:14 2003

Date: Thu, 23 Oct 2003 03:05:11 -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, 23 Oct 2003     Volume: 10 Number: 5700

Today's topics:
    Re: c programmer in need of perl advise <jminicoz@optonline.net>
    Re: commands, which is better <gmiller@NOTforSPAM.gregmiller.net>
    Re: commands, which is better (Villy Kruse)
    Re: file redirect within back ticks not working (Tad McClellan)
        Fill up HD fastest way drunkenfist@bazurk.com
    Re: Fill up HD fastest way <tassilo.parseval@rwth-aachen.de>
    Re: Fill up HD fastest way (Sam Holden)
    Re: Fill up HD fastest way <kalinaubears@iinet.net.au>
        help to understand a broken script (Chad)
    Re: help to understand a broken script <jurgenex@hotmail.com>
    Re: help to understand a broken script <jayanth.vs@in.bosch.com>
    Re: help to understand a broken script <tassilo.parseval@rwth-aachen.de>
        Is there a better way than using $+ ? <neil.shadrach@bt.com>
    Re: my first perl script! (Tad McClellan)
    Re: my first perl script! <jminicoz@optonline.net>
    Re: my first perl script! <tassilo.parseval@rwth-aachen.de>
        Newbie Regex Help <jayanth.vs@in.bosch.com>
    Re: Newbie Regex Help <noreply@gunnar.cc>
    Re: Newbie Regex Help <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Newbie Regex Help (Philip Lees)
    Re: Newbie Regex Help chance@austin.rr.com
    Re: Pattern match over mutiple files is slow - Help Nee (Tad McClellan)
    Re: performance arrays vs hashes (Tad McClellan)
    Re: performance arrays vs hashes <jminicoz@optonline.net>
    Re: Perl & Apache: modifying index.html while it's used <gmiller@NOTforSPAM.gregmiller.net>
    Re: Perl and IIS - script runs but 'The page cannot be  (stew dean)
    Re: Perl and IIS - script runs but 'The page cannot be  (stew dean)
    Re: Perl and IIS - script runs but 'The page cannot be  (stew dean)
        print (...) interpreted as function (was Re: Oddity wit <abigail@abigail.nl>
        Referring to a 'column' from a reference to an array of (fatted)
    Re: Referring to a 'column' from a reference to an arra (Anno Siegel)
        Strange file opening problem on WinNT (Michael)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Oct 2003 05:26:02 GMT
From: "Joe Minicozzi" <jminicoz@optonline.net>
Subject: Re: c programmer in need of perl advise
Message-Id: <KDJlb.3879$F8.1047466@news4.srv.hcvlny.cv.net>


"Greg Patnude" <gpatnude@adelphia.net> wrote in message
news:ZDylb.124175$qj6.7331906@news1.news.adelphia.net...
> Its called "slurping" a file -- the so-called "pros" claim it is not
really
> "recommended" but I do it all the time with absolutely no consequence and
no
> obvious performance hit until the files exceed 6 MB or so ...
>
>  if (open (DATA, "$FILENAME")) {
>
>     @DATA = <DATA>;
>
> }
>
> you can read more about it in the Perl FAQ -->
>
>
http://www.perldoc.com/perl5.6/pod/perlfaq5.html#How-can-I-read-in-an-entire
-file-all-at-once-
>
> --
> Greg Patnude / The Digital Demention
> 2916 East Upper Hayden Lake Road
> Hayden Lake, ID 83835
> (208) 762-0762
>
> "Mike Deskevich" <mikedeskevich@yahoo.com> wrote in message
> news:71734b21.0310220826.52f8a9cf@posting.google.com...
> > i have a quick (hopefully) question for the perl gurus out there.  i
> > have a bunch of data files that i need to read in and do some
> > processing.  the data files are simple two columns of (floating point)
> > numbers, but the size of the file can range from 1000 to 10,000 lines.
> >  i need to save the data in an array for post processing, so i can't
> > just read a line and throw the data away.  my main question is: is
> > there a faster way to read the data than how i'm currently doing it
> > (i'm a c programmer, so i'm sure that i'm not using perl as
> > efficiently as i can)
> >
> > here's how i read my data files
> >
> > $ct=0;
> > while (<DATAFILE>)
> > {
> >   ($xvalue[$ct],$yvalue[$ct])=split;
> >   $ct++;
> > }
> > #do stuff with xvalue and yvalue
> >
> > is there a more efficient way to read in two columns of numbers?  it
> > turns out that i have a series of these data files to process and i
> > think that most of the time is being used in either perl start up
> > time, or data reading time, the post processing is happening pretty
> > fast (i think)
> >
> > thanks,
> > mike
>
>

Not intending to be picky, but "slurping" a file usually means reading the
entire file into a single scalar variable as a string.  This is done by
setting $/ to undef before the read.





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

Date: Thu, 23 Oct 2003 04:27:10 GMT
From: Greg Miller <gmiller@NOTforSPAM.gregmiller.net>
Subject: Re: commands, which is better
Message-Id: <b1mepvkcf3kdl4u14m0kgmrc9276d9lchi@4ax.com>

On Tue, 21 Oct 2003 10:44:42 -0400, Robert Wallace
<robertw@nospam.acm.org> wrote:

>#  this one ##########################################################
>open (SYS, "/temp/uptime.exe |");
>while($the_sys = <SYS>){
>    $the_sys =~ s/\015\012/<br>\015\012/g;
>    print $the_sys . "<br>\n";
>}
>close (SYS);
>
>
>#  and this one
>##########################################################
>$sys=`/temp/uptime.exe`;
>$sys=~s/\015\012/<br>\015\012/g;
>print $sys;

	In addition to what they others said:  in the first example,
if the output of the uptime.exe program pauses long enough for the
perl program to catch up, the while loop will terminate even if the
program outputs more data later.  IIRC

Greg Miller   gmiller@gregmiller.net    http://www.gregmiller.net


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

Date: 23 Oct 2003 07:08:17 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: commands, which is better
Message-Id: <slrnbpevj6.1l9.vek@station02.ohout.pharmapartners.nl>

On Thu, 23 Oct 2003 04:27:10 GMT,
    Greg Miller <gmiller@NOTforSPAM.gregmiller.net> wrote:


>On Tue, 21 Oct 2003 10:44:42 -0400, Robert Wallace
><robertw@nospam.acm.org> wrote:
>
>>#  this one ##########################################################
>>open (SYS, "/temp/uptime.exe |");
>>while($the_sys = <SYS>){
>>    $the_sys =~ s/\015\012/<br>\015\012/g;
>>    print $the_sys . "<br>\n";
>>}
>>close (SYS);
>>
>>
>>#  and this one
>>##########################################################
>>$sys=`/temp/uptime.exe`;
>>$sys=~s/\015\012/<br>\015\012/g;
>>print $sys;
>
>	In addition to what they others said:  in the first example,
>if the output of the uptime.exe program pauses long enough for the
>perl program to catch up, the while loop will terminate even if the
>program outputs more data later.  IIRC
>
A


I don't think so.  Reading from a pipe will return the eof condition
only when the other end of the pipe is closed.  If the pipe temporarily
runs empty the reader will be suspended until more data is sent in in
the other end or the other end is closed down.


Villy


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

Date: Wed, 22 Oct 2003 23:19:48 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: file redirect within back ticks not working
Message-Id: <slrnbpeln4.691.tadmc@magna.augustmail.com>

ktom <abc@nowhere.com> wrote:
> from with a perl script this line does not work
                                    ^^^^^^^^^^^^^
> `sed -e 1,14d $file >> /tmp/junk`;
> 
> it seems the redirect does not work.
                        ^^^^^^^^^^^^^

What did you expect it to do?

What did it do instead?


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


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

Date: 23 Oct 2003 09:26:29 GMT
From: drunkenfist@bazurk.com
Subject: Fill up HD fastest way
Message-Id: <3f979ec5$0$58701$e4fe514c@news.xs4all.nl>


Hi,

I'm writing a Perl script that fills a HD with random data as fast as possible.

open(FILE,'>garbage.dat');
while(1) { print FILE rand() } 

This is terribly slow, so I did some tweaking:

open(FILE,'>garbage.dat');
while(1) {
    print FILE (rand() x 10000) 
}

ha, that one is a lot faster!

Any faster way?



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

Date: 23 Oct 2003 09:42:19 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Fill up HD fastest way
Message-Id: <bn87pr$ir0$1@nets3.rz.RWTH-Aachen.DE>

Also sprach drunkenfist@bazurk.com:

> I'm writing a Perl script that fills a HD with random data as fast as possible.
> 
> open(FILE,'>garbage.dat');
> while(1) { print FILE rand() } 
> 
> This is terribly slow, so I did some tweaking:
> 
> open(FILE,'>garbage.dat');
> while(1) {
>     print FILE (rand() x 10000) 
> }
> 
> ha, that one is a lot faster!
> 
> Any faster way?

Yes. 

    system "cat /dev/urandom > garbage.dat";

Of course, this makes some gentle assumptions, like the existence of
/dev/urandom and cat(1).

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 23 Oct 2003 09:54:23 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Fill up HD fastest way
Message-Id: <slrnbpf9af.56b.sholden@flexal.cs.usyd.edu.au>

On 23 Oct 2003 09:26:29 GMT,
	drunkenfist@bazurk.com <drunkenfist@bazurk.com> wrote:
> 
> Hi,
> 
> I'm writing a Perl script that fills a HD with random data as fast as possible.
> 
> open(FILE,'>garbage.dat');
> while(1) { print FILE rand() } 
> 
> This is terribly slow, so I did some tweaking:
> 
> open(FILE,'>garbage.dat');
> while(1) {
>     print FILE (rand() x 10000) 
> }
> 
> ha, that one is a lot faster!

And a lot less "random"...



-- 
Sam Holden


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

Date: Thu, 23 Oct 2003 19:56:51 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Fill up HD fastest way
Message-Id: <3f97a69c$0$23605$5a62ac22@freenews.iinet.net.au>

drunkenfist@bazurk.com wrote:
> Hi,
> 
> I'm writing a Perl script that fills a HD with random data as fast as possible.
> 
> open(FILE,'>garbage.dat');
> while(1) { print FILE rand() } 
> 
> This is terribly slow, so I did some tweaking:
> 
> open(FILE,'>garbage.dat');
> while(1) {
>     print FILE (rand() x 10000) 
> }
> 

The same "random" number will be repeated 10000 times.
Not my idea of a HD full of "random" data :-)

Cheers,
Rob

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



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

Date: 23 Oct 2003 00:30:04 -0700
From: chussung@operamail.com (Chad)
Subject: help to understand a broken script
Message-Id: <97a530bb.0310222330.552f582f@posting.google.com>

I am still trying to learn perl. I know there are basic rename scripts
out there, but I am trying to make one as a learning tool.

The script should take a directory from the prompt and make a renamed
copy in the same directory replacing spaces with underscores. It seems
to do everything except the actual file copy.

It's not that I need this program. Instead I would be gratefull for
any insight and undestanding as to why it does not work.

Thank you 
Chad
---

#!/usr/bin/perl
use File::Copy;

$output = `cmd 2>&1`;		#trying to see errors


$olddirname = $ARGV[0];
$newdirname = "$olddirname.new";

opendir(DirNameold,"$olddirname") or die "could not open
directory:$olddirname";

while (defined($file = readdir DirNameold )) {

	$newfilename = $file;
	$newfilename =~ tr/ /_/;
	copy("$file","$newfilename") unless $file eq $newfilename;

};

---


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

Date: Thu, 23 Oct 2003 07:39:29 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: help to understand a broken script
Message-Id: <RALlb.31060$Ee6.10671@nwrddc01.gnilink.net>

Chad wrote:
> I am still trying to learn perl. I know there are basic rename scripts
> out there, but I am trying to make one as a learning tool.
>
> The script should take a directory from the prompt and make a renamed
> copy in the same directory replacing spaces with underscores. It seems
> to do everything except the actual file copy.
>
> It's not that I need this program. Instead I would be gratefull for
> any insight and undestanding as to why it does not work.
>
> Thank you
> Chad
> ---
>
> #!/usr/bin/perl

You should always ask for as much help from perl as possible.
Right at the beginning you are missing a

    use strict;
    use warnings;

> use File::Copy;

Good!

[...]
> copy("$file","$newfilename") unless $file eq $newfilename;

And here you are missing the fail condition.
Besides, that is a useless use of quotes.

    {copy($file, $newfilename) or die "Can't copy $file to $newfilename
because $!"}
        unless $file eq $newfilename;

I didn't analyse you program any further because it is humiliating to ask a
human to do work that a machine can do better and faster.
The actual error message should give you a hint about what is wrong.

jue




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

Date: Thu, 23 Oct 2003 13:59:40 +0530
From: "JSV" <jayanth.vs@in.bosch.com>
Subject: Re: help to understand a broken script
Message-Id: <bn83hp$b9m$1@ns2.fe.internet.bosch.com>


"Chad" <chussung@operamail.com> wrote in message
news:97a530bb.0310222330.552f582f@posting.google.com...
> I am still trying to learn perl. I know there are basic rename scripts
> out there, but I am trying to make one as a learning tool.
>
<snip>

> It's not that I need this program. Instead I would be gratefull for
> any insight and undestanding as to why it does not work.
>
>
<snip>
> copy("$file","$newfilename") unless $file eq $newfilename;

I guess, you are executing this copy command, when not present inside the
directory passed in $ARGV[0]. Also trap error by using die "$!" after the
copy.




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

Date: 23 Oct 2003 08:30:59 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: help to understand a broken script
Message-Id: <bn83k3$e5j$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Jürgen Exner:

> Chad wrote:

>> copy("$file","$newfilename") unless $file eq $newfilename;
> 
> And here you are missing the fail condition.
> Besides, that is a useless use of quotes.
> 
>     {copy($file, $newfilename) or die "Can't copy $file to $newfilename
> because $!"}
>         unless $file eq $newfilename;

That's a syntax error. You can't (yet) use statement modifiers on bare
blocks. You don't even need a block. Simply

    copy($file, $newfilename) 
        or die "Can't copy $file to $newfilename because $!"
            unless $file eq $newfilename;

will do.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 23 Oct 2003 08:42:19 +0000 (UTC)
From: Neil Shadrach <neil.shadrach@bt.com>
Subject: Is there a better way than using $+ ?
Message-Id: <bn849b$q21$3@visp.bt.co.uk>

Ok I worked out an answer in the process of putting the question together so it's not desperate :)
However a neater solution would be welcome if anyone has the enthusiasm.

#!/usr/bin/perl
use strict;
use warnings;

my $result;
foreach my $count (1..2)
{
   my $s=qq(line $count goes first);
   foreach my $p (qr/line . goes first/,qr/line (.) goes first/,qr/line (.) goes (\w+)/)
   {
     my @a;
     print q(String="),$s,q(" Pattern="),$p,q(" Result=),$result++,q( match=),join(q(:),@a),q( $+=),defined $+?"def":"not","\
n" if @a=$s=~$p;
   }
}

The above script produces the following results.

String="line 1 goes first" Pattern="(?-xism:line . goes first)" Result=0 match=1 $+=not
String="line 1 goes first" Pattern="(?-xism:line (.) goes first)" Result=1 match=1 $+=def
String="line 1 goes first" Pattern="(?-xism:line (.) goes (\w+))" Result=2 match=1:first $+=def
String="line 2 goes first" Pattern="(?-xism:line . goes first)" Result=3 match=1 $+=not
String="line 2 goes first" Pattern="(?-xism:line (.) goes first)" Result=4 match=2 $+=def
String="line 2 goes first" Pattern="(?-xism:line (.) goes (\w+))" Result=5 match=2:first $+=def

I want to discriminate between result 0 and result 1.
In the first case match equals 1 because the match succeeded while in the second case it equals 1 because
that happens to be the string matched by the first () - that is @a always has at least one value in the
event of a match with no parenthesis in the pattern or one pair both resulting in exactly one value.
I want to call a function in the event of a match with an array of the captured () values.
I could use (defined $+)?@a:()) but I'm wondering if I could have arranged it such that @a was empty in
the result 0 case.

Thanks



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

Date: Wed, 22 Oct 2003 23:10:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: my first perl script!
Message-Id: <slrnbpel69.691.tadmc@magna.augustmail.com>

Matthias Wille <willema@student.ethz.ch> wrote:
> Am Mon, 20 Oct 2003 11:19:46 +0000 schrieb Tassilo v. Parseval:

>>> $lines = join("", <OLD>);

>> However, there's a better way to slurp in a whole file:

>>     my $lines = do {
>>         local $/;   # enable "slurp" mode
>>         <OLD>;
>>     };

> And why is your 'slurp'-method exactly better? is it faster?


   perldoc Benchmark

:-)

      
> Or do you know if it is possible to match
> the following string with a reasonable simple regexp?


Sure! 

This one is pretty simple:

   /.*/s

and it will match that string.

This one is even simpler and will also match:

   //


Want to rephrase your question?  :-)


   Is it possible to match balanced/nested things like the
   curly brackets in the following string?


> Case = SOME_CASE {
> 
>    subcase1 = {.....}
>    ....	
>    subcase2 = {......}
> 
> )
  ^
  ^ I sure hope that was supposed to be a {curly} bracket character...


> The whole block should be matched, but how do I tell the regexp not to
> match the inner brackets?


The inner brackets are enclosed in the "whole block" so they
_must_ be matched if you want the whole block to be matched...

Want to rephrase that question too?  :-)  :-)


   How do I tell the regex to match the _corresponding_
   closing curly bracket?


I think this Perl FAQ answers what you meant to ask:

   Can I use Perl regular expressions to match balanced text?


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


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

Date: Thu, 23 Oct 2003 06:14:16 GMT
From: "Joe Minicozzi" <jminicoz@optonline.net>
Subject: Re: my first perl script!
Message-Id: <YkKlb.4755$F8.1176017@news4.srv.hcvlny.cv.net>


"Matthias Wille" <willema@student.ethz.ch> wrote in message
news:pan.2003.10.22.19.37.01.168653@student.ethz.ch...
[snip]
> I started about 1 Week ago with perl programming and I think i got the
> main principles by now. But I'm a computer scientist, so I already have
> experience with programming and understand the basic programming concepts.
> So learning a new programming language is just a matter of learning new
> syntax, although Perl has quite some constructs I have never seen in other
> languages.... very interesting!
>
> Greetings
> Matthias

Perl has the often useful and sometimes maddening characteristic of having
"assimilated" features from a number of languages.  ("Resistance is
futile.")  It has features of C, the UNIX C/system call library, UNIX
shells, a bit of SED/AWK, a bit of C++/Java and possibly some Lisp (which I
don't know so I can't say).  So if you are familiar with those, Perl can
look fairly familiar.  The maddening part is that some of the assimilated
features are juuuust a little different, which can trip you up.  I've been
working with Perl for 5 years and I always have either the "Camel" book or
the Perl docs at hand, so I can double-check things like syntax, semantics
and argument order.




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

Date: 23 Oct 2003 07:28:58 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: my first perl script!
Message-Id: <bn7vvq$ajf$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Matthias Wille:

> Am Mon, 20 Oct 2003 11:19:46 +0000 schrieb Tassilo v. Parseval:

>>> # read all lines of isildap.ini file
>>> $lines = join("", <OLD>);
>> 
>>     my $lines = join "", <OLD>;
>> 
>> However, there's a better way to slurp in a whole file:
>> 
>>     open OLD, ...;
>>     my $lines = do {
>>         local $/;   # enable "slurp" mode
>>         <OLD>;
>>     };

[...]

> And why is your 'slurp'-method exactly better? is it faster?

It is likely to be faster, yes. But also, it might make the intention of
the code clearer. It is a common idiom for slurping so fellow
programmers could quickly reckognize what the code is supposed to do.

> ok, I rewrote the whole section, because it didn't work to match what i
> wanted with regular expressions. Or do you know if it is possible to match
> the following string with a reasonable simple regexp?
> 
> Case = SOME_CASE {
> 
>    subcase1 = {.....}
>    ....	
>    subcase2 = {......}
> 
> )
> 
> The whole block should be matched, but how do I tell the regexp not to
> match the inner brackets?

You want a reasonably simple regex, but there is none for this task. It
would have to be recursive, that is: the regexp containing itself. But as
Anno Siegel recently said: it's an obscenity. Using Text::Balanced is an
easier and more robust solution.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 23 Oct 2003 11:04:59 +0530
From: "Jayanth S Vasisht" <jayanth.vs@in.bosch.com>
Subject: Newbie Regex Help
Message-Id: <bn7pah$2b6$1@ns2.fe.internet.bosch.com>

Hello,
  I am trying to use Regex for some of my scripts. My requirements is as
follows,

I am trying to process the output of a command from Rational Clearcase. The
output I get is something like this
/main/1a_br_1/tmp_fix_2.2.0/14

From this, I would like to get the number after the last "/", i.e 14. It is
fixed, that after the last "/", there will be digits. Any ideas, how I could
achieve this by using regex.

Thanks,
Jayanth
~~~~~






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

Date: Thu, 23 Oct 2003 07:49:31 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie Regex Help
Message-Id: <bn7qbu$u0d5f$1@ID-184292.news.uni-berlin.de>

Jayanth S Vasisht wrote:
> 
> /main/1a_br_1/tmp_fix_2.2.0/14
> 
> From this, I would like to get the number after the last "/", i.e
> 14. It is fixed, that after the last "/", there will be digits.

     ($number) = $output =~ /.+\/(\d+)/;

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



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

Date: Thu, 23 Oct 2003 05:54:35 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Newbie Regex Help
Message-Id: <Xns941D5042A2DDFelhber1lidotechnet@62.89.127.66>

"Jayanth S Vasisht" <jayanth.vs@in.bosch.com> wrote in
news:bn7pah$2b6$1@ns2.fe.internet.bosch.com: 

> Hello,
>   I am trying to use Regex for some of my scripts. My requirements is
>   as 
> follows,
> 
> I am trying to process the output of a command from Rational
> Clearcase. The output I get is something like this
> /main/1a_br_1/tmp_fix_2.2.0/14
> 
> From this, I would like to get the number after the last "/", i.e 14.
> It is fixed, that after the last "/", there will be digits. Any ideas,
> how I could achieve this by using regex.


Two methods come to mind (both assume your data is in $_):


  my ($thingy) = m#.*/(.*)#;


or


  my $thingy = (split /\//)[-1];



Cheers,
Bernard


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

Date: Thu, 23 Oct 2003 06:06:24 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Newbie Regex Help
Message-Id: <3f976f79.59858093@news.grnet.gr>

On Thu, 23 Oct 2003 11:04:59 +0530, "Jayanth S Vasisht"
<jayanth.vs@in.bosch.com> wrote:

>I am trying to process the output of a command from Rational Clearcase. The
>output I get is something like this
>/main/1a_br_1/tmp_fix_2.2.0/14
>
>From this, I would like to get the number after the last "/", i.e 14. It is
>fixed, that after the last "/", there will be digits. Any ideas, how I could
>achieve this by using regex.

if ( /(\d+)$/{
    print "Found $1\n";
}else{
    # something wrong
}


Phil
-- 
Ignore coming events if you wish to send me e-mail


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

Date: Thu, 23 Oct 2003 06:11:59 GMT
From: chance@austin.rr.com
Subject: Re: Newbie Regex Help
Message-Id: <bn7rir$g72$1@localhost.localdomain>

Jayanth S Vasisht <jayanth.vs@in.bosch.com> wrote:
> Hello,
>   I am trying to use Regex for some of my scripts. My requirements is as
> follows,

> I am trying to process the output of a command from Rational Clearcase. The
> output I get is something like this
> /main/1a_br_1/tmp_fix_2.2.0/14

> From this, I would like to get the number after the last "/", i.e 14. It is
> fixed, that after the last "/", there will be digits. Any ideas, how I could
> achieve this by using regex.

> Thanks,
> Jayanth
> ~~~~~



#!/usr/bin/perl 

use strict;
use warnings; 

my $test_string = '/main/1a_br_1/tmp_fix_2.2.0/14';

# [\d] means 'a digit'
# [\d]+ means 1 or more digits
# ([\d]+) means remember the actual string that triggered a match here
#    and save it to $1 ---- since this is first occurence of parenthises
#    in regex. next parenthisized thing, if it exists will go in $2.
#    $1,$2 ... etc may get side effected by all kinds of stuff, so grab
#    these right away for dependable results
# $, at the end of a regeex, means 'end of string'
# \/ means /

$test_string =~ m/\/([\d]+)$/ || die;

my $last_hunk_o_digits = $1;

print "$last_hunk_o_digits\n";

-- 
I used to think government was a necessary evil.
I'm not so sure about the necessary part anymore.


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

Date: Wed, 22 Oct 2003 22:53:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Pattern match over mutiple files is slow - Help Needed !
Message-Id: <slrnbpek6m.691.tadmc@magna.augustmail.com>

Darren Dunham <ddunham@redwood.taos.com> wrote:

> # compile regex with all keys in it.
> my $re_str = join "|", @keylist;


This one bit me once, so I'll mention it to save reader's
from experiencing similar pain.


Better make that:

   my $re_str = join "|", sort {$b cmp $a} @keylist;

(or sort keylist in descending order when it is populated.)

  /one|onerous/   # onerous _never_ matches

  /onerous|one/   # much better


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


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

Date: Wed, 22 Oct 2003 23:24:12 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: performance arrays vs hashes
Message-Id: <slrnbpelvc.691.tadmc@magna.augustmail.com>

Joe Minicozzi <jminicoz@optonline.net> wrote:

> You _can_ say "$hash{'abcd'}" or "$hash{'whatever I damn well
> please'}" and actually, you don't need the quotes;


You don't need the quotes when the key matches /^\w+$/.

So you need the quotes for something like that 2nd one above.


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


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

Date: Thu, 23 Oct 2003 05:51:00 GMT
From: "Joe Minicozzi" <jminicoz@optonline.net>
Subject: Re: performance arrays vs hashes
Message-Id: <8%Jlb.4334$F8.1116709@news4.srv.hcvlny.cv.net>


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbpelvc.691.tadmc@magna.augustmail.com...
> Joe Minicozzi <jminicoz@optonline.net> wrote:
>
> > You _can_ say "$hash{'abcd'}" or "$hash{'whatever I damn well
> > please'}" and actually, you don't need the quotes;
>
>
> You don't need the quotes when the key matches /^\w+$/.
>
> So you need the quotes for something like that 2nd one above.
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

Oops.  Thanks for pointing that out.  I did RTFM, but I didn't CRTFM
(Carefully ...).





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

Date: Thu, 23 Oct 2003 04:13:36 GMT
From: Greg Miller <gmiller@NOTforSPAM.gregmiller.net>
Subject: Re: Perl & Apache: modifying index.html while it's used
Message-Id: <spkepv86n9shcj65mhocf9cok7vn4mnijb@4ax.com>

On 20 Oct 2003 09:58:38 -0700, brendan@symonty.org (brendan) wrote:

>Sure, I had a feeling that might be the best approach.  Does Apache
>cope alright with having a file being renamed like this?

	On UNIX you'll be fine, on Windows I don't know.  But even if
there is a possibility for a problem to occur, it would be in that
minuscule amount of time it takes to delete the old one and rename the
new one, giving users a 404 error.  But it's much better than just
overwriting the file, so users could possibly get a half done file.

Greg Miller   gmiller@gregmiller.net    http://www.gregmiller.net


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

Date: 23 Oct 2003 02:22:26 -0700
From: stewart@webslave.dircon.co.uk (stew dean)
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <2b68957a.0310230122.5e72c4f4@posting.google.com>

jwillmore@myrealbox.com (James Willmore) wrote in message news:<d61170e5.0310221726.7b4f6315@posting.google.com>...
> stewart@webslave.dircon.co.uk (stew dean) wrote in message news:<2b68957a.0310221410.141f9d3f@posting.google.com>...
> > James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<20031022114233.1492c7aa.jwillmore@remove.adelphia.net>...
> > > On 22 Oct 2003 04:27:54 -0700
> > > stewart@webslave.dircon.co.uk (stew dean) wrote:
> > > > James Willmore <jwillmore@remove.adelphia.net> wrote in message
> > > > news:<20031021114710.504263f7.jwillmore@remove.adelphia.net>...
> > > > > On 21 Oct 2003 03:53:24 -0700
> > > > > stewart@webslave.dircon.co.uk (stew dean) wrote:
> > > <snip>
> > > 
> > > What happened when you ran the script at the command line? 
> > 
> > I've never run a perl script at the command line. 
> 
> Why not?

Because I've never had to. Why would I want to?


> > >  There is
> > > _little_ difference between running the script on the command line and
> > > running it through the web server - especially if you use the CGI
> > > module (hint - '-debug').
>  
> > > Where is the code you speak of?  You have yet to post any offending
> > > code.
> > 
> > There is no offending code. I'm not posting up my script as the script
> > works fine. It takes an XML file and spits out other files (html) and
> > one HTML page which tells me the script has run and gives me more
> > options (like adding details to selected pages).
> > 
> > > The documentation for _Perl_  (specifically, perlfaq9) gives a tip or
> > > two on debugging a buggy Perl CGI script.  
> > 
> > The perl script is not buggy - it's running fine. It generates all the
> > files but for some reason is not producing my final HTML page.
> 
> Hum ... are you outputing the correct HTTP header?

Yes.

>  Maybe there _is_
> something wrong with the script?  A typo, maybe?  Running the script
> _at the command line_ will produce messages that _may_ not be seen as
> errors, but as warnings that the web server is just dismissing. 

All errors that are generated by the script are displayed in the
output. It uses strict so all errors are picked up including variables
not declared. If it finds more than one it stops running and tells me.

Now there may be errors produced of a different kind but then this
would be new to me and I'm trying to find out what kind of errors they
may be. The code it's self is fine with no syntax errors.

If I run it from the command line it can't find the input file as the
file is relative to the web server. This is all about reading and
writing files afterall.

<snip>

> > > For the time being - and to give a hint - try using CGI::Carp (just
> > > not in a production environment).
> > 
> > Well that's enigmatic. I suspect that it's also not the answer I seek
> > but I will check it out.
> 
> Like I mentioned before, maybe the code _is_ broke somewhere. 
> CGI::Carp can report the errors  to the browser (since you seem to not
> want to run the script at the command line).  If something is broke,
> the error will appear.

If something is  broke it gives me the error by passing me the
headers. Will Carp give me any errors that I don't already receive
(given that I'm not adding debug messages into the script)?

Stew Dean


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

Date: 23 Oct 2003 02:29:29 -0700
From: stewart@webslave.dircon.co.uk (stew dean)
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <2b68957a.0310230129.3fa00227@posting.google.com>

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<mjFlb.28443$Ee6.26897@nwrddc01.gnilink.net>...
> stew dean wrote:
> > The perl script is not buggy - it's running fine.
> 
> Then what is your problem? Apparently it has nothing to do with Perl or has
> it?

It's to do with the way perl is running on IIS - that is for some
reason it is running but the output is not reaching the browser.

It's also about finding out more about how Perl runs on windows. 

Perl doesnt naturaly have an error log on windows from what I can see
and so far I have been relying on the errors given to me in the
headers returned -that is the usualy syntax and other errors that are
returned by using strict.

Now I'm exploring all the other suggestions but so far I've had not
joy.

Stew Dean


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

Date: 23 Oct 2003 02:45:14 -0700
From: stewart@webslave.dircon.co.uk (stew dean)
Subject: Re: Perl and IIS - script runs but 'The page cannot be displayed'
Message-Id: <2b68957a.0310230145.498158bc@posting.google.com>

"Alan J. Flavell" <flavell@ph.gla.ac.uk> wrote in message news:<Pine.LNX.4.53.0310230029460.11611@ppepc56.ph.gla.ac.uk>...
> On Wed, 22 Oct 2003, stew dean acidicly remarked for the benefit of
> the gallery:
> 
> > Thanks for what is probably the only helpful responce so far.
> 
> I think that's reached the plonk threshold now.  Bye.

Hang on - why does your name ring a bell?  My god - it's the same Alan
Flavell I used to talk about HTML to way back in 1996. You where the
one who was saying HTML should not be used for layout. You even
suggested that all layout should be done in PDF at one point. Shame I
missed all your wining about Flash and what about style sheets?

Welcome to 2003 Alan. 

Stew Dean


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

Date: 23 Oct 2003 09:01:32 GMT
From: Abigail <abigail@abigail.nl>
Subject: print (...) interpreted as function (was Re: Oddity with the x and . operators)
Message-Id: <slrnbpf67c.6dl.abigail@alexandra.abigail.nl>

Darren Dunham (ddunham@redwood.taos.com) wrote on MMMDCCIV September
MCMXCIII in <URL:news:IzBlb.5669$Oh4.5305@newssvr29.news.prodigy.com>:
!!  
!!  One of the warnings is...
!!  print (...) interpreted as function at -e line 1.

<rant>

This is one of the most useless and annoying warnings there is.
I find it so annoying that I patched my perl and ripped it out.

Pop quiz, which of the following will emit the warning?
Answer after the formfeed.

1:  print(3 + 4) * 5;


2:  print  (3 + 4) * 5;


3:  if (1) {
        print ("Hello")
    }


4:  print (")");


5:  {
        print (3), next if 1;
    }


6:  {
        print(3), "next" if 1;
    }




Answers: it gives the warning in the cases 3, 4 and 5, and doesn't
emit the warning in 1, 2 and 6. However, the cases 3, 4, and 5 are
*correct*, while the cases 1, 2 and 6 have problems.

It got *all* cases wrong.

Luckily(?) this test is only done with print, printf and sort.
It's thought that accidently parsing it as a function will only
happen with these three functions, but never with other functions.

</rant>


Abigail
-- 
perl -wle 'print prototype sub "Just another Perl Hacker" {};'


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

Date: 23 Oct 2003 01:38:39 -0700
From: obeseted@yahoo.com (fatted)
Subject: Referring to a 'column' from a reference to an array of array references
Message-Id: <9edc36a2.0310230038.5e362cb6@posting.google.com>

The DBI module has a function fetchall_arrayref which returns a
reference to an array of references to arrays. Its quite easy to refer
to a row of the matrix:

$row_ref = $array_ref->[0];

(which would correspond to 1 row retrieved from database table), but I
can't think of how to refer to a column of the matrix (corresponds to
all the various values for a particular field / column).
Is it possible to refer to a column using array referencing of some
description? (I know how to iterate over the array and suck out each
column value, I'm just wondering whether there is as easy a way as
when referring to rows). I'd normally iterate using a
foreach/while/for loop or maybe a map function, can anyone think of
alternatives (some sort of array slice or something?).

Cheers,


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

Date: 23 Oct 2003 09:23:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Referring to a 'column' from a reference to an array of array references
Message-Id: <bn86lm$h69$1@mamenchi.zrz.TU-Berlin.DE>

fatted <obeseted@yahoo.com> wrote in comp.lang.perl.misc:
> The DBI module has a function fetchall_arrayref which returns a
> reference to an array of references to arrays. Its quite easy to refer
> to a row of the matrix:
> 
> $row_ref = $array_ref->[0];
> 
> (which would correspond to 1 row retrieved from database table), but I
> can't think of how to refer to a column of the matrix (corresponds to
> all the various values for a particular field / column).
> Is it possible to refer to a column using array referencing of some
> description? (I know how to iterate over the array and suck out each
> column value, I'm just wondering whether there is as easy a way as
> when referring to rows). I'd normally iterate using a
> foreach/while/for loop or maybe a map function, can anyone think of
> alternatives (some sort of array slice or something?).

Wait for Perl 6 for multi-dimensional array slices.  In Perl 5 you'll
need a loop to extract a row: "map $_->[ $col], @$array_ref".

Anno


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

Date: 23 Oct 2003 02:03:36 -0700
From: mps25@cam.ac.uk (Michael)
Subject: Strange file opening problem on WinNT
Message-Id: <2b8bae76.0310230103.37a5afc9@posting.google.com>

I've tried hard to google an answer to this without success. I'm using
a perl script on Windows NT (Perl 5.8.0) that I've written (and
executed with no problem) on a Linux machine. The script uses the
command (acting on a plain text file):

$comm=join("","output\\",$data_type,"_",$date,".mps");
open(INFILE,$comm);
 ....
$close(INFILE);

The file is read no problem (and, in fact, writes out to another file
no problem). The strange thing about running it in Windows is that it
ALSO "executes" the file it reads: in the same sense as if I double
clicked on the file. So ".dat" files (associated with Excel here)
cause lots of excel windows to pop up if I read in lots of files. I
changed to an unassociated extension to avoid this and a pop-up
appears to tell me (for each and every file) that the file cannot be
executed as it is not associated with an application.

The program still works but makes a fast script very slow. If anyone
knows what's going on, could they let me know?

Michael


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

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.  

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

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

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


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


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