[24369] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6558 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 13 11:05:52 2004

Date: Thu, 13 May 2004 08:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 13 May 2004     Volume: 10 Number: 6558

Today's topics:
        "Definitive Guide to OOP in Perl"? <socyl@987jk.com>
        "my" variables and recursive regexp strangeness (Ian)
    Re: "my" variables and recursive regexp strangeness (Anno Siegel)
    Re: "my" variables and recursive regexp strangeness <noreply@gunnar.cc>
        error installing perl 5.8.4 with useithreads (Hasanuddin Tamir)
        file clipper <pippolino@ANTISPAMfreemail.it>
    Re: file clipper (Anno Siegel)
    Re: Finding the newest directory (Sam Holden)
    Re: Finding the newest directory <Joe.Smith@inwap.com>
        Help Me Understand this <georgekinley@hotmail.com>
    Re: Help Me Understand this <tadmc@augustmail.com>
        how to represent  hash  in pseudo code (perl) <velu_jayashree@yahoo.com>
    Re: how to represent  hash  in pseudo code (perl) (Malcolm Dew-Jones)
    Re: how to represent  hash  in pseudo code (perl) <cwilbur@mithril.chromatico.net>
        Perl binary distribution with threads support (Yash)
    Re: Perl binary distribution with threads support <jack_challen@ocsl.co.uk>
        Perl multiline command syntax <s.usenet@nigel.com.au>
    Re: Perl multiline command syntax <ittyspam@yahoo.com>
    Re: Perl multiline command syntax <trammell+usenet@hypersloth.invalid>
    Re: Perl multiline command syntax <ThomasKratz@REMOVEwebCAPS.de>
    Re: Perl multiline command syntax <spam@nowhere.com>
    Re: Perl multiline command syntax <ittyspam@yahoo.com>
        PERL script to tidy e-mail <e01@removethis.toao.net>
        PERL with Thread.pm (Charlie)
    Re: PERL with Thread.pm <jack_challen@ocsl.co.uk>
        Skipping content  in Array within loop and go to the ne <ewijaya@singnet.com.sg>
    Re: Skipping content  in Array within loop and go to th <tadmc@augustmail.com>
    Re: Skipping content  in Array within loop and go to th <ewijaya@singnet.com.sg>
    Re: Skipping content  in Array within loop and go to th <thepoet_nospam@arcor.de>
        Stopping code execution in RE's <mb@uq.net.au.invalid>
    Re: Stopping code execution in RE's <mb@uq.net.au.invalid>
    Re: Stopping code execution in RE's (Anno Siegel)
        Template.pm and file uploads? (Bill)
        Time Complexity for substr() function <ewijaya@singnet.com.sg>
    Re: Using hashes to sort number sequences <gnari@simnet.is>
        Why Carp::croak over die? <nomail_please@nomail.org>
    Re: Why Carp::croak over die? ctcgag@hotmail.com
    Re: Why Carp::croak over die? <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 13 May 2004 14:46:26 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: "Definitive Guide to OOP in Perl"?
Message-Id: <c801o2$enq$1@reader2.panix.com>





I just came across (in the 2003.09.25 manpage for Graham Barr's
Scalar::Util v. 1.13) a reference to "the APress book `Tuomas J.
Lukka's Definitive Guide to Object-Oriented Programming in Perl'".
Since I can't find this book in print anywhere (and no mention of
it at the APress site) I assume that it has not been published yet.
Does anyone know of the status of this book? Is it still in the
works, or was the project abandoned?

kj

P.S. I already own a copy of Conway' "Object Oriented Perl", which
I think is pretty good, but I find the subject inexhaustible.
-- 
NOTE: In my address everything before the period is backwards.


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

Date: 13 May 2004 06:21:03 -0700
From: ijnetnews@hotmail.com (Ian)
Subject: "my" variables and recursive regexp strangeness
Message-Id: <942d3706.0405130521.34d2ba7f@posting.google.com>

I have something strange happening with a recursive regexp compiled
with qr//x; It is a regular expression to match individual single
double and un-quoted strings, i.e. "string", 'string' and string.

It works fine when the sub parts of it are global variables, or
"local" variables, but if I change them to "my" variables, suddenly
they stop matching correctly (or at least start matching differently).

Anybody have any ideas why changing to "my" variables would affect it
this way?

I get the same behaviour using active perl 5.6.1, and perl 5.81 on
knoppix.

Other things I'd like to know if anybody has any idea are:
Is there a simpler way to regexp this kind of thing?
Why does perl crash with some recursive regexps?
Is there any particular reason for the warning generated when this
script is run using perl -W

I use test input something like:
aaa bbb "ccc"'ddd"ddd'"eee'eee" f\ \ \ ff

Here's the program, if you change the first two vars to "my" variables
it stops working. changing others don't seem to affect it.


#!perl

# Double-quoted-string data regexp
$dStringData = qr/
    ([^"\\]|\\.)+ (??{$dStringData})
    |
    "
    /x;

# Single-quoted-string data regexp
$sStringData = qr/
    ([^'\\]|\\.)+ (??{$sStringData})
    |
    '
    /x;

# Characters that are allowed in unquoted strings
$token = qr/([^\s\\'"]|\\.)/x;

# Unquoted-strings broken up by spaces regexp
$uStringData = qr/
    (??{$token})+ (??{$uStringData})
    |
    \B|\b
    /x;

# Matches single or double, single or unquoted strings
$string = qr/
    (
        (??{$token}) (??{$uStringData})
        |
        " (??{$dStringData})
        |
        ' (??{$sStringData})
    )
    /x;

# Test program to identify "STRING"s or 'STRING's or STRINGs in the
input

while (<>) {
    my @strings;

# remove them all one by one
    while (/$string/) {
        push @strings, $1;
        s/$string//;
    }

# print out of all them one by one
    my $counter = 0;
    foreach (@strings) {
        print "$counter = [$_]\n";
        $counter ++;
    }
}


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

Date: 13 May 2004 14:00:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "my" variables and recursive regexp strangeness
Message-Id: <c7vv2n$25k$1@mamenchi.zrz.TU-Berlin.DE>

Ian <ijnetnews@hotmail.com> wrote in comp.lang.perl.misc:
> I have something strange happening with a recursive regexp compiled
> with qr//x; It is a regular expression to match individual single
> double and un-quoted strings, i.e. "string", 'string' and string.
> 
> It works fine when the sub parts of it are global variables, or
> "local" variables, but if I change them to "my" variables, suddenly
> they stop matching correctly (or at least start matching differently).
> 
> Anybody have any ideas why changing to "my" variables would affect it
> this way?

It isn't the fact that they're lexical, but you apparently tried
to declare the variables in the same statement that uses them,
as in

    my $dStringData = qr/
        ([^"\\]|\\.)+ (??{$dStringData})
        |
        "
    /x;

You can't use a lexical in the same statement that declares it.
Use an extra "my" statement, and it works.

It would have been better to post the erroneous code, instead of
saying "if I change this, it doesn't work anymore".  That way
we wouldn't have to guess your error.

Anno


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

Date: Thu, 13 May 2004 16:25:53 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: "my" variables and recursive regexp strangeness
Message-Id: <2gheqjF2sg2uU1@uni-berlin.de>

Ian wrote:
> I have something strange happening with a recursive regexp compiled
> with qr//x; It is a regular expression to match individual single
> double and un-quoted strings, i.e. "string", 'string' and string.
> 
> It works fine when the sub parts of it are global variables, or
> "local" variables, but if I change them to "my" variables, suddenly
> they stop matching correctly (or at least start matching
> differently).

You'd better my() declare those variables before they are used:

     my $dStringData;
     $dStringData = qr/

etc. (Otherwise it's too late.)

> Other things I'd like to know if anybody has any idea are: Is there
> a simpler way to regexp this kind of thing?

This would do something similar:

     my $token = qr/[^\s\\'"]|\\./;
     while (<>) {
         my @strings;
         push @strings, $+ while /('[^']*')|("[^"]*")|($token+)/g;
         print "$_ = [$strings[$_]]\n" for 0..$#strings;
     }

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



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

Date: 13 May 2004 06:01:52 -0700
From: hasant@m-net.arbornet.org (Hasanuddin Tamir)
Subject: error installing perl 5.8.4 with useithreads
Message-Id: <7109f8c3.0405130501.563aeffd@posting.google.com>

Hi all,

I was trying to install perl 5.8.4 with -Duseithreads and -Dmultiplicity,
and I got this error when doing ./perl ../ext/threads/shared/t/wait.t from
t directory.

Too many arguments for threads::shared::cond_wait_enabled at
 ../ext/threads/shared/t/wait.t line 132
(also for line 133)

The reason I did the ./perl is because 'make test' failed for that wait.t.
Is there any body know how to fix this, or point some direction?

Google didn't have any record matching the error string, both the web and
group version. This discussion group never discussed it before. No one
talks about it at perl.com and perl.org. I think this is pretty normal
considering that 5.8.4 was just released recently (May 05, 2004).

TIA,
san


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

Date: Thu, 13 May 2004 10:33:19 +0200
From: pippolino <pippolino@ANTISPAMfreemail.it>
Subject: file clipper
Message-Id: <slrnca6cmf.3sb.pippolino@pingu.linuxbox.lan>

i want to write a clipper which scans a file for each occurence of a regexp 
like /<div>.*<\/div>/ and put it on a scalar concatenating it with .= or simply
prints it out... It seems simple but the only ways i know to access file is line
by line or char by char so i have to scan first for <div> and use another regexp
to look for the </div> which is on another line... is there a way to do it with
a single regexp, or, i don't think it will be a good solutions, scan the whole
file at the same time?!
thanks everyone who wants to help me!

-- 
[Filippo...........................]
[Linux User #342745................]
[remove ANTISPAM for reply.........]
        ==[...penguin powered...]==


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

Date: 13 May 2004 09:08:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: file clipper
Message-Id: <c7vdtm$jdr$2@mamenchi.zrz.TU-Berlin.DE>

pippolino  <pippolino@ANTISPAMfreemail.it> wrote in comp.lang.perl.misc:
> i want to write a clipper which scans a file for each occurence of a regexp 
> like /<div>.*<\/div>/ and put it on a scalar concatenating it with .= or simply
> prints it out... It seems simple but the only ways i know to access file is line
> by line or char by char so i have to scan first for <div> and use another regexp
> to look for the </div> which is on another line... is there a way to do it with
> a single regexp, or, i don't think it will be a good solutions, scan the whole
> file at the same time?!
> thanks everyone who wants to help me!

That is only the beginning of the difficulties.  Others are nested tags,
tags appearing in comments, and some more.  Consider one of the
HTML-parsing modules.

Anno


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

Date: 13 May 2004 04:05:05 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Finding the newest directory
Message-Id: <slrnca5svh.jnd.sholden@flexal.cs.usyd.edu.au>

On Thu, 13 May 2004 03:09:51 +0000 (UTC),
	Ben Morrow <usenet@morrow.me.uk> wrote:
> 
> Quoth sholden@cs.usyd.edu.au:
>> On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <sc0ri0n@hotmail.com> wrote:
>> > Hi,
>> > 
>> > If I have a bunch of directories and files (sun solaris). Is there a way to
>> > find the newest directory (last one created not modified)?
>> 
>> No (unless you are using a funky non-standard file system).
>> 
>> Creation time is not tracked by the filesystem.
>> 
>> You have (most recent) access time, modification time, and
>> file status time. File status time (ctime) is as close as
>> you'll get, but it is set by other operations that change
>> the file status (such as chmod(), link(), unlink(), etc.)
>> 
>> stat gives you access to the ctime.
> 
> ...and you'll likely want File::Find to do the searching.
> 
> OTOH, you could probably do this more easily with find(1).

I thought about find(1), but it finds all the files that match
the expression you give it. I don't know how to tell it to
output just the newest, or the biggest, of the anythingest for
that matter.

My first guess would be something like:

my $the_winner;
{
  my $the_winners_ctime;
  for (get_the_directory_paths()) {
      my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
          $atime,$mtime,$ctime,$blksize,$blocks) = stat;
      if (!defined $the_winner or $the_winners_ctime < $ctime) {
          $the_winner = $_;
	  $the_winners_ctime = $ctime;
      }
  }
}
print "$the_winner\n";

But ctime gets set by write(2) so the whole thing is pointless...

-- 
Sam Holden



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

Date: Thu, 13 May 2004 07:48:28 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Finding the newest directory
Message-Id: <gLFoc.2987$1q3.365620@attbi_s51>

sc0ri0n wrote:

> Sam,
> 
> I am not interested in files at all.  There is a process that creates
> directories. What I need to do is to detect the one created last and move
> all of its content.
> 
> Also, I am new to unix so I am not sure if there are other statistics for
> directories like last modified or last accessed as in files?

foreach my $entry (glob '*') {
   print +(-d $entry ? 'Directory' : 'File'), " $entry is ", -s _, " bytes\n";
   printf "  Modified %6.2f days ago\n", -M _;
   printf "  Accessed %6.2f days ago\n", -A _;
   printf "  Changed  %6.2f days ago\n", -C _;
}

	-Joe


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

Date: Thu, 13 May 2004 07:09:36 GMT
From: "George Kinley" <georgekinley@hotmail.com>
Subject: Help Me Understand this
Message-Id: <QaFoc.16263$k4.327971@news1.nokia.com>

Hi
I am learning to use "Format" function , most of the things I can understand
except how to write to different FILEHANDLE
use FileHandle;

OUTF->format_name("My_Other_Format");

OUTF->format_top_name("My_Top_Format");

I know this stunt works, but I cant understand how it works,

Another thing Which I would appreciate if some one can show how to add
commas in Integer number inside "format"

--






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

Date: Thu, 13 May 2004 06:30:45 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help Me Understand this
Message-Id: <slrnca6n35.7tb.tadmc@magna.augustmail.com>

George Kinley <georgekinley@hotmail.com> wrote:

> Subject: Help Me Understand this


Please put the subject of your article in the Subject of your article.


> Another thing Which I would appreciate if some one can show how to add
> commas in Integer number 


   perldoc -q commas

       How can I output my numbers with commas added?


> inside "format"


Use the FAQ answer and put the result in a scalar.

Treat the scalar as a string within the format.


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


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

Date: Thu, 13 May 2004 00:26:49 -0400
From: "maami" <velu_jayashree@yahoo.com>
Subject: how to represent  hash  in pseudo code (perl)
Message-Id: <60bca47b2db20c56f031ee8f3e770912@localhost.talkaboutprogramming.com>

hai,
         i want to write the pseudo code for the perl program.In such case
iam using hash.I want to know that how to represent the hash in the pseudo
code.
if suppose iam using arrays means then,
 i will mention it as,
       a[i] = a[j]
 ...........
 .......  and so on.
so,
plz tell me how to represent the hash in it.

regards,
Jayashree




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

Date: 12 May 2004 21:55:09 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: how to represent  hash  in pseudo code (perl)
Message-Id: <40a2ffad@news.victoria.tc.ca>

maami (velu_jayashree@yahoo.com) wrote:
: hai,
:          i want to write the pseudo code for the perl program.In such case
: iam using hash.I want to know that how to represent the hash in the pseudo
: code.
: if suppose iam using arrays means then,
:  i will mention it as,
:        a[i] = a[j]
: ...........
: .......  and so on.
: so,
: plz tell me how to represent the hash in it.

?

perhaps

	%hash1 = ( a_key => "it's value" , another_key => "value 2" );

	$hash1{'a_key'}       = "alter the value for the first key";
	$hash1{'another_key'} = "and now change the second value as well";

	
	$hash2_ref = { a_key => "different hash, different value"};



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

Date: Thu, 13 May 2004 08:59:16 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: how to represent  hash  in pseudo code (perl)
Message-Id: <87ekpoaeso.fsf@mithril.chromatico.net>

>>>>> "maami" == maami  <velu_jayashree@yahoo.com> writes:

    maami> hai, i want to write the pseudo code for the perl
    maami> program. In such case iam using hash.I want to know that how
    maami> to represent the hash in the pseudo code.  

If you're doing it for your own benefit, do whatever makes sense to
you.  If you're doing it for the benefit of someone else, do whatever
makes sense to him or her.  There is no standard way of writing
pseudocode.

Charlton

-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


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

Date: 13 May 2004 06:02:55 -0700
From: yashgt@yahoo.com (Yash)
Subject: Perl binary distribution with threads support
Message-Id: <5a373b1d.0405130502.4a8b50c@posting.google.com>

Hi,
Can anyone point me to a Perl binary distribution for HP-UX 11i with
support for threads?
The one at http://hpux.connect.org.uk/hppd/hpux/Languages/perl-5.8.3/
has been compiled without threads support.


If I run my program I get the following message:
This Perl has neither ithreads nor 5005threads at
/usr/local/lib/perl5/5.8.3/Thread.pm line 335
BEGIN failed--compilation aborted at
/usr/local/lib/perl5/5.8.3/Thread.pm line 335.
Compilation failed in require at ./prog.pl line 307.

Also, if I do /usr/local/bin/perl -V,
it gives:
Summary of my perl5 (revision 5.0 version 8 subversion 3)
configuration:
  Platform:
    osname=hpux, osvers=11.00, archname=PA-RISC2.0
    uname='hp-ux ness b.11.00 a 9000780 2012209406 two-user license '
    config_args='-d -e -Dcc=gcc -Dprefix=/usr/local useposix=true'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
which means the perl has not been compiled with threads support.


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

Date: Thu, 13 May 2004 15:02:52 +0100
From: Jack Challen <jack_challen@ocsl.co.uk>
Subject: Re: Perl binary distribution with threads support
Message-Id: <leLoc.3$Ox3.480@psinet-eu-nl>

Yash wrote:
> Hi,
> Can anyone point me to a Perl binary distribution for HP-UX 11i with
> support for threads?
> The one at http://hpux.connect.org.uk/hppd/hpux/Languages/perl-5.8.3/
> has been compiled without threads support.

HP's supplied version has been compiled with thread support.

You can get it from 
http://www.software.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL

-or-
http://tinyurl.com/2cfjt

I'm pretty sure that that version has been compiled with HP's Ansi C 
compiler, so you may run into problems when installing XS modules though.

Cheers
jack


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

Date: Thu, 13 May 2004 11:35:54 +0930
From: Nigel <s.usenet@nigel.com.au>
Subject: Perl multiline command syntax
Message-Id: <eol5a051pcompdsjns3q57a75pv8ehgth2@4ax.com>

Hello

I am trying to use perl to find and replace in a large text file but I
cannot seem to get it to search over multiple lines.

# cat file.txt | perl -p - i -e
's/pattern(.*)endofpattern/replacement/g'

I have tried many combinations but whatever I try, I can only get it
to search line by line.  I have read everywhere about using /m but i
dont understand where to use it.

Can someone please help me.


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

Date: Thu, 13 May 2004 10:19:23 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Perl multiline command syntax
Message-Id: <20040513101321.T15402@dishwasher.cs.rpi.edu>

On Thu, 13 May 2004, Nigel wrote:

> Hello
>
> I am trying to use perl to find and replace in a large text file but I
> cannot seem to get it to search over multiple lines.
>
> # cat file.txt | perl -p - i -e
> 's/pattern(.*)endofpattern/replacement/g'
>
> I have tried many combinations but whatever I try, I can only get it
> to search line by line.  I have read everywhere about using /m but i
> dont understand where to use it.
>
> Can someone please help me.

First, you need to tell Perl to read the whole file in as one string,
rather than line by line.  Otherwise, your s/// is only operating on one
line at a time.  To do this, supply the -0777 switch (see perldoc perlrun
for more info here).

Second, you need to tell the search-and-replace that . should match *any*
character, including a newline.  By default, . does not match newlines.
To do this, provide the /s switch to the regexp.  (The /m switch has
nothing to do with this issue - it's used to change the $ and ^ anchors,
which aren't used here).

Third, why are you bothering to invoke a cat process, rather than just
feeding the relevant file to the perl oneliner?


perl -0777 -pi -e 's/pattern.*endofpattern/replacement/gs' file.txt

(note that I removed the parens because $1 wasn't being used.  If your
actual replacement does use $1, add the parens back in.)

Hope this helps,
Paul Lalli


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

Date: Thu, 13 May 2004 14:24:06 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: Perl multiline command syntax
Message-Id: <slrnca7186.e6p.trammell+usenet@hypersloth.el-swifto.com.invalid>

On Thu, 13 May 2004 11:35:54 +0930, Nigel <s.usenet@nigel.com.au> wrote:
> I am trying to use perl to find and replace in a large text file but I
> cannot seem to get it to search over multiple lines.
> 
> # cat file.txt | perl -p - i -e
> 's/pattern(.*)endofpattern/replacement/g'

I think this is explained well in the "perlrun" manpage; look at the
documentation for the "-p" and "-0" options.  (That's a zero, not an
"oh".)

Two more comments:
* you want "-i", not "- i"
* you don't need to use "cat"--you can do this (untested):

  perl -pi -0777 -e 'whatever' file.txt



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

Date: Thu, 13 May 2004 16:28:02 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Perl multiline command syntax
Message-Id: <40a38766.0@juno.wiesbaden.netsurf.de>

Nigel wrote:

> Hello
> 
> I am trying to use perl to find and replace in a large text file but I
> cannot seem to get it to search over multiple lines.
> 
> # cat file.txt | perl -p - i -e
> 's/pattern(.*)endofpattern/replacement/g'
> 
> I have tried many combinations but whatever I try, I can only get it
> to search line by line.  I have read everywhere about using /m but i
> dont understand where to use it.

the /m modifier won't help here because it changes the behaviour of the 
anchors ^ and $. You want /s because it lets . match a newline.

Also your pattern will only match once because the (.*) will eat up all 
characters between the first occurence of 'pattern' and the *last* 
occurence of 'endofpattern'. You have to switch to non-greedy matching by 
putting a '?' after the quantifier.

So try:
    's/pattern(.*?)endofpattern/replacement/sg'

And then reread 'perldoc perlre' again, and again, .... ;-)
You'll need more than a few rereads before you get familiar with it (I 
sure did).

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..


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

Date: Thu, 13 May 2004 09:20:35 -0500
From: Todd <spam@nowhere.com>
Subject: Re: Perl multiline command syntax
Message-Id: <c8007j$ai1$2@home.itg.ti.com>

Nigel wrote:

> Hello
> 
> I am trying to use perl to find and replace in a large text file but I
> cannot seem to get it to search over multiple lines.
> 
> # cat file.txt | perl -p - i -e
> 's/pattern(.*)endofpattern/replacement/g'
> 
> I have tried many combinations but whatever I try, I can only get it
> to search line by line.  I have read everywhere about using /m but i
> dont understand where to use it.
> 
> Can someone please help me.
This works for me.  It makes a backup copy and fixes the file.

	perl -i.old -p -e "s/old_string/new_string/g" file.txt

Todd


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

Date: Thu, 13 May 2004 11:00:10 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Perl multiline command syntax
Message-Id: <20040513105846.H15402@dishwasher.cs.rpi.edu>

On Thu, 13 May 2004, Todd wrote:

> Nigel wrote:
>
> > Hello
> >
> > I am trying to use perl to find and replace in a large text file but I
> > cannot seem to get it to search over multiple lines.
> >
> > # cat file.txt | perl -p - i -e
> > 's/pattern(.*)endofpattern/replacement/g'
> >
> > I have tried many combinations but whatever I try, I can only get it
> > to search line by line.  I have read everywhere about using /m but i
> > dont understand where to use it.
> >
> > Can someone please help me.
> This works for me.  It makes a backup copy and fixes the file.
>
> 	perl -i.old -p -e "s/old_string/new_string/g" file.txt

No it doesn't.  At least, it doesn't do what the OP asked for.  The OP was
specifically asking about making a search-and-replace where the pattern
spans multiple lines.  Your code does not do that.  See other replies in
this thread.

Paul Lalli


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

Date: Thu, 13 May 2004 15:02:29 GMT
From: "Experienced but Undocumented" <e01@removethis.toao.net>
Subject: PERL script to tidy e-mail
Message-Id: <96Moc.2727$9P6.1151@clgrps12>

Does anyone know of a PERL script to tidy up line breaks and quote marks (>)
from e-mail message bodies?

Thanks




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

Date: 12 May 2004 23:17:09 -0700
From: cji_work@yahoo.com (Charlie)
Subject: PERL with Thread.pm
Message-Id: <1dc70d61.0405122217.62e61784@posting.google.com>

Hi folks, 
The version of perl that I am using on my company's linux machine is
5.6.1, which does not include Thread.pm. And it happens that I need to
have some perl  scripts created on my home PC to be running on that
platform, and those scripts "use Thread".

I was looking for the necessary modules from www.cpan.org to add on
and what I realize is I had to add the whole perl package to have it
included. So here is my question:
1. Is there some "patches" that just has this part included, not the
whole perl install package?
2. If I have to have the whole Perl 5.8.4 or high version installed on
linux, what the minimum installation size going to be?  Also any tips
for the installation? I guess if I am going to do it, it would be done
in my home dir, otherwise the requst would take days to finish.
3. If for any reason, I have to use the existing perl, what I might do
to work around, following are the only part of code that uses Thread
in that scripts.
"
 ....
use Thread;
my $thread1 = Thread->new(\&func1);
my $thread2 = Thread->new(\&func2);
my $thread3 = Thread->new(\&func3);
$_->join foreach($thread1, $thread2, $thread3);
"

thanks for the tips. 



CJ


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

Date: Thu, 13 May 2004 13:02:37 +0100
From: Jack Challen <jack_challen@ocsl.co.uk>
Subject: Re: PERL with Thread.pm
Message-Id: <CtJoc.2$Ox3.445@psinet-eu-nl>

Charlie wrote:
> 1. Is there some "patches" that just has this part included, not the
> whole perl install package?

Not really, it's an option that you'd have to supply when building Perl 
yourself from the source code (-DUSETHREADS IIRC). It's not just a matter 
of adding a couple of modules.

Some distributions may have taken to building perl with threads enabled - 
you should check to see if you've got the latest package of perl available 
for your distribution, and if there's a thread-enabled version available.

hope that helps.

jack


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

Date: Thu, 13 May 2004 12:09:10 -0000
From: Edward Wijaya <ewijaya@singnet.com.sg>
Subject: Skipping content  in Array within loop and go to the next (of NEXT function)
Message-Id: <opr7xtdk1zuj0cst@news.singnet.com.sg>

Hi,
If I have this construct

MYLABEL : foreach $arr1 (@arr1)
	{
		for (my $k=0; $k<100 ;k++)
		while (some expression) {
		if (some expression)
		{ do something;
               NEXT MYLABEL:}
		else {do another thing;}
             }
        }

I want to know if the NEXT is executed the loop continue the subsequent 
list content or not,
or it start all over again by taking the first array value.

If the latter is the case, is there anyway I can make the loop continue 
with subsequent
value instead of starting from the first array?

Thanks so much for your time.
Hope to hear from you again.

Regards
Edward WIJAYA


-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


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

Date: Thu, 13 May 2004 00:04:08 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Skipping content  in Array within loop and go to the next (of NEXT function)
Message-Id: <slrnca60e8.747.tadmc@magna.augustmail.com>

Edward Wijaya <ewijaya@singnet.com.sg> wrote:


> MYLABEL : foreach $arr1 (@arr1)

>                NEXT MYLABEL:}
                             ^
                             ^ that does not belong there

> I want to know if the NEXT 


Surely you meant "next" instead? Case matters you know.


> is executed the loop continue the subsequent 
> list content or not,
> or it start all over again by taking the first array value.


What happened when you tried it?


Have you read the documentation for next() ?

   perldoc -f next

      ... it starts the next iteration of the loop


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


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

Date: Thu, 13 May 2004 22:14:19 -0000
From: Edward Wijaya <ewijaya@singnet.com.sg>
Subject: Re: Skipping content  in Array within loop and go to the next (of NEXT function)
Message-Id: <opr7yld5ghuj0cst@news.singnet.com.sg>

On Thu, 13 May 2004 00:04:08 -0500, Tad McClellan <tadmc@augustmail.com> 
wrote:
Hi

> Edward Wijaya <ewijaya@singnet.com.sg> wrote:
>
>
>> MYLABEL : foreach $arr1 (@arr1)
>
>>                NEXT MYLABEL:}
>                              ^
>                              ^ that does not belong there
>
>> I want to know if the NEXT
>
>
> Surely you meant "next" instead? Case matters you know.
Yes. Sorry for my carelessness, Tad. Thanks for pointing
it out.


>
>
>> is executed the loop continue the subsequent
>> list content or not,
>> or it start all over again by taking the first array value.
>
>
> What happened when you tried it?
It excecute the array's contents and it doesn't
give infinite loop. But the output is to large
to check whether it satisfy the condition.

>
>
> Have you read the documentation for next() ?
>
>    perldoc -f next
Not the man page, but the Camel Book (Chapter 2.6).


>
>       ... it starts the next iteration of the loop

Admit I was uncareful to notice and interpret
that statement in that book. Thanks Tad.

>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


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

Date: Thu, 13 May 2004 07:50:35 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Skipping content  in Array within loop and go to the next (of NEXT function)
Message-Id: <40a30cab$0$1862$9b4e6d93@newsread2.arcor-online.net>

Edward Wijaya schrieb:
> I want to know if the NEXT is executed the loop continue the subsequent 
> list content or not,
> or it start all over again by taking the first array value.

Did you look at "perldoc -f next"?

<quote>
     next    The "next" command is like the "continue" statement in C; it
             starts the next iteration of the loop:
</quote>

So it should be clear that "next" makes the foreach
behave just like it reached the end of its code block
and carry on with the next step. Otherwise Larry would
have called it "first" instead of "next" ;-)

But what is so dificult about doing a little test?

C:\>perl -e "@arr=(1,2,3,4,5); foreach(@arr){ print $_.$/; next }"
1
2
3
4
5
C:\>

HTH
-Christian


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

Date: Thu, 13 May 2004 14:36:31 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Stopping code execution in RE's
Message-Id: <c7uu0f$u3a$1@bunyip.cc.uq.edu.au>

Hi all,

OK, first off - the perldocs for RE's make my head hurt :)

I'm writing a formatter package that basically has a little language of its own 
to allow joombie users format their own stuff without bothering me....

One of the formatter 'tags' allows the use of a regular expression (in a 
slightly stunted fashion), however I want to ensure no code execution is performed.

RE's are specified like:

find /RE/, REFLAGS

REFLAGS can be a string containing 'ismx' - anything else causes an error.
RE is a (duh) regular expression. This is split into RE strings (for instance 
'^[a-z]\Q$FOO\E') and variables (for instance $FOO, @BAR etc).

The variable handling is done - that was pretty easy.

Technically the RE handling is pretty easy too - I could just rebuild it by 
evaluating the variables and plonking it all back together, eg

store $BAR, 'BAR[]!'
find /^[a-z](\Q$FOO\E$BAR)\z/, 'is', FIELD

=> RE is split into '^[a-z](\Q$FOO\E', $BAR, ')\z';
=> $BAR evaluates to 'BAR[]!' -> quote it with '\QBAR[]!\E';
=> $RE is built into '(?is:^[a-z](\Q$FOO\E\QBAR[]!\E)\z)';
$FIELD =~ $re;
etc etc... (obviously done so that it actually works....)

The problem here is if the user does something like:

find /(?{system('rm -rf /')})/, '', FIELD

This is obviously not something I want to run. Is there a simple thing I can do 
to stop RE's from ever executing inline code, or do I have to add checks for 
this to my RE parser?

MB



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

Date: Thu, 13 May 2004 15:36:41 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: Stopping code execution in RE's
Message-Id: <c7v1h9$i4c$1@bunyip.cc.uq.edu.au>

Matthew Braid wrote:

<snip>
> The problem here is if the user does something like:
> 
> find /(?{system('rm -rf /')})/, '', FIELD
> 
> This is obviously not something I want to run. Is there a simple thing I 
> can do to stop RE's from ever executing inline code, or do I have to add 
> checks for this to my RE parser?

I'm replying to myself, but I've found one slightly non-ugly solution....

If I insert an artificial variable into the re mix, execution is disallowed.

For example, if I have a variable called $null with a value of '', and I build 
the RE like so:

	eval "\$re = qr/\$null$re/$reflags";
	$field =~ $re;

then if the user specified RE has (?{ print "ARGH!" }) in it it fails with the 
error:

  Eval-group not allowed at runtime, use re 'eval' in regex m/....

but the re is OK if no eval groups are included.

Obviously I'm never gonna use re 'eval'.

On a side note, I'm not happy using eval "..." but I have to do that for the \Q, 
\L, \U, \E tags.... May be I'll just parse for them earlier and convert things 
myself....



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

Date: 13 May 2004 09:04:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Stopping code execution in RE's
Message-Id: <c7vdne$jdr$1@mamenchi.zrz.TU-Berlin.DE>

Matthew Braid  <mb@uq.net.au.invalid> wrote in comp.lang.perl.misc:
> Matthew Braid wrote:
> 
> <snip>
> > The problem here is if the user does something like:
> > 
> > find /(?{system('rm -rf /')})/, '', FIELD
> > 
> > This is obviously not something I want to run. Is there a simple thing I 
> > can do to stop RE's from ever executing inline code, or do I have to add 
> > checks for this to my RE parser?
> 
> I'm replying to myself, but I've found one slightly non-ugly solution....
> 
> If I insert an artificial variable into the re mix, execution is disallowed.
> 
> For example, if I have a variable called $null with a value of '', and I build 
> the RE like so:
> 
> 	eval "\$re = qr/\$null$re/$reflags";

No big deal, but you don't have to do the assignment inside eval.

        $re = eval "qr/\$null$re/$reflags";

> 	$field =~ $re;
> 
> then if the user specified RE has (?{ print "ARGH!" }) in it it fails with the 
> error:
> 
>   Eval-group not allowed at runtime, use re 'eval' in regex m/....
> 
> but the re is OK if no eval groups are included.
> 
> Obviously I'm never gonna use re 'eval'.
> 
> On a side note, I'm not happy using eval "..." but I have to do that for
> the \Q, 
> \L, \U, \E tags.... May be I'll just parse for them earlier and convert things 
> myself....

In full generality, "eval" will be hard to avoid, but you *can* reduce
its use to the extraction of variable values.  Something like this

    for my $varname ( $regex =~ /(\$[A-Za-z_]\w*)/g ) {
        my $val = eval "qq($varname)";
        $varname = '\\' . $varname;
        $regex =~ s/$varname/$val/g;
    }
    my $re = qr/$regex/;

This expands the variable values right inside the regex string.  It may
need quite a bit of refinement, I'm being sketchy here.

I'm wondering how the user knows what variables they can use.  If they
are user-defined variables, the user can do their own interpolation,
so I assume the variables are defined in your program.  But then
the user needs some kind of catalog of what variables are available.

In that case you could build a hash of all possible variable names
and their (string) values and substitute according to that.  No
eval is needed.

Anno


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

Date: 13 May 2004 07:10:38 -0700
From: wherrera@lynxview.com (Bill)
Subject: Template.pm and file uploads?
Message-Id: <239ce42f.0405130610.6257c345@posting.google.com>

Has anyone successfully used Template.pm in CGI file upload routines?
I know how to use CGI.pm to do this, but wonder if multipart HTML
pages can be used with Template.pm?


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

Date: Thu, 13 May 2004 22:21:03 -0000
From: Edward Wijaya <ewijaya@singnet.com.sg>
Subject: Time Complexity for substr() function
Message-Id: <opr7ylpdkkuj0cst@news.singnet.com.sg>

Hi,

Any idea of the time complexity of the substr()
in Perl?

Is it under linear time?

Any reference I can go to for that?

Thanks for your time.
Hope to hear from you again.

Regards
Edward WIJAYA
SINGAPORE

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


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

Date: Thu, 13 May 2004 08:34:41 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Using hashes to sort number sequences
Message-Id: <c7vbs1$lc5$1@news.simnet.is>

"Martin Foster" <mdfoster44@netscape.net> wrote in message
news:6a20f90a.0405121531.2862676d@posting.google.com...

[ comparing multi-length records in 2 huge files]

you definitely want to sort the files.
then you only have to make one pass through each,
only keeping 2 records in memory at the same time.

if sorting is not an option, maybe you could make
one prelimininary pass through each file, storing
the file offset for the start of each record in
a hash keyed to the record identifier

gnari






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

Date: Thu, 13 May 2004 12:52:18 +0000 (UTC)
From: Irving Kimura <nomail_please@nomail.org>
Subject: Why Carp::croak over die?
Message-Id: <c7vr22$cdu$1@reader2.panix.com>






I often come across the advice to use Carp::croak instead of die,
presumably because croak reports the error "from the perspective
of the caller", but I don't understand why this is generally
considered so much better.

If I'm interested in the caller's perspective, I use the Perl
equivalent of try/catch (i.e. eval/if($@)).  This gives me access
to information both about the caller *and* about the called function.

Am I missing something?

Thanks!

Irv

-- 


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

Date: 13 May 2004 14:44:49 GMT
From: ctcgag@hotmail.com
Subject: Re: Why Carp::croak over die?
Message-Id: <20040513104449.265$eT@newsreader.com>

Irving Kimura <nomail_please@nomail.org> wrote:
> I often come across the advice to use Carp::croak instead of die,
> presumably because croak reports the error "from the perspective
> of the caller", but I don't understand why this is generally
> considered so much better.

If my module is dying due to some internal error, it should die.
If it is dying because the user did something wrong, it should croak.

> If I'm interested in the caller's perspective, I use the Perl
> equivalent of try/catch (i.e. eval/if($@)).

You wrap every single call to everything outside your own code in eval
blocks?  I would think that that makes for butt-ugly code.  And what do you
do in all those thousands of if($@) blocks?

> This gives me access
> to information both about the caller *and* about the called function.
>
> Am I missing something?

Yes.  Clean, readable, simple code.


Xho

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


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

Date: Thu, 13 May 2004 14:47:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why Carp::croak over die?
Message-Id: <c801po$i2i$1@wisteria.csv.warwick.ac.uk>


Quoth Irving Kimura <nomail_please@nomail.org>:
> 
> I often come across the advice to use Carp::croak instead of die,
> presumably because croak reports the error "from the perspective
> of the caller", but I don't understand why this is generally
> considered so much better.
> 
> If I'm interested in the caller's perspective, I use the Perl
> equivalent of try/catch (i.e. eval/if($@)).  This gives me access
> to information both about the caller *and* about the called function.
> 
> Am I missing something?

Carp is for use in modules, where the error message is addressed to the
user of the module. That is, if you write a module:

package Foo;

sub bar {
    my ($file) = @_;
    open my $FH, '<', $file or die "can't open $file: $!";
}

and put it up on CPAN, a user will be rather confused when they supply
the name of a nonexistent file and it dies with '...at Foo.pm line xxx'.
They would have to grovel around in the source of your module to work
out what they'd done wrong, and try to trace the logic back to find out
where they had called Foo::bar with an incorrect argument. If, however,
it dies with '...at footest.pl line yyy' they can immediately see where
their mistake is, and correct it.

Carp doesn't actually simply report from the perspective of the caller.
It is quite clever about working out where the actual mistake was; for
instance

package Foo;

sub bar {
    baz @_;
}

sub baz {
    open my $FH, '<', $_[0] or croak "can't open $file: $!";
}

will report the error as coming from the caller of Foo::bar, even though
the croak happened in Foo::baz.

When I'm writing modules, I use carp/croak for things which are the
user's fault, and warn/die for things which are my fault (obviously,
such things never happen :).

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

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


Administrivia:

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

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

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

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

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


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


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