[17239] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4661 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 19 06:10:29 2000

Date: Thu, 19 Oct 2000 03:10:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971950215-v9-i4661@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 19 Oct 2000     Volume: 9 Number: 4661

Today's topics:
        Regexp as input strings <sba@ocegr.fr>
    Re: Regexp as input strings <uri@sysarch.com>
    Re: Rijndael in Perl (those who know me have no need of my name)
    Re: Search, pad, replace (Martien Verbruggen)
    Re: Sort Help Needed <uri@sysarch.com>
        string extraction gelshocker@my-deja.com
    Re: string extraction (Bernard El-Hagin)
    Re: string extraction (Logan Shaw)
    Re: string extraction gelshocker@my-deja.com
    Re: Tele Commute ONLY - PERL - Java - JS - CSS - HTML - <bill.kemp@wire2.com>
    Re: value exchange of two vars <bernie@fantasyfarm.com>
    Re: value exchange of two vars <bart.lateur@skynet.be>
    Re: weird print behaviorr <ubl@schaffhausen.de>
    Re: whence $0 (Randal L. Schwartz)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 19 Oct 2000 10:03:35 +0200
From: Stephane Barizien <sba@ocegr.fr>
Subject: Regexp as input strings
Message-Id: <39EEAAD7.82323E49@ocegr.fr>

Hi folks,

That's probably an AFAQ (Awfully Frequently Asked Question) but I really
cannot find the answer...

I wanna match one string against as set of regexp patterns which are
themselves stored in strings.

The following works:

@patternlist = ("kernel", "bar", "windows[\s\n]*nt");
$str = "kernel steve Windows\nnt";

@compiled = map { qr/$_/im } @patternlist;

print "$str\n";

foreach $pat (@compiled)
{
	print "$pat: ";
	if ($str =~ /$pat/)
	{
		print "Y\n";
	}
	else
	{
		print "N\n";
	}
}

but the pattern matching options are hardcoded in the qr// operator,
whereas I would like to have them in the pattern strings:

@patternlist = ("/kernel/i", "/bar/", "/windows[\s\n]*nt/im");
$str = "kernel steve Windows\nnt";

@compiled = map { qr/$_/ } @patternlist;

print "$str\n";

foreach $pat (@compiled)
{
	print "$pat: ";
	if ($str =~ /$pat/)
	{
		print "Y\n";
	}
	else
	{
		print "N\n";
	}
}



but that doesn't work as the qr// will compile "/kernel/i" literally --
match against the string "/kernel/i", not case-insensitively against
"kernel".

Any clue?


TIA


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

Date: Thu, 19 Oct 2000 08:09:36 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Regexp as input strings
Message-Id: <x7u2a9qmkf.fsf@home.sysarch.com>

>>>>> "SB" == Stephane Barizien <sba@ocegr.fr> writes:

  SB> That's probably an AFAQ (Awfully Frequently Asked Question) but I
  SB> really cannot find the answer...

i don't think it is an FAQ at all.

  SB> but the pattern matching options are hardcoded in the qr// operator,
  SB> whereas I would like to have them in the pattern strings:

  SB> @patternlist = ("/kernel/i", "/bar/", "/windows[\s\n]*nt/im");

  SB> but that doesn't work as the qr// will compile "/kernel/i" literally --
  SB> match against the string "/kernel/i", not case-insensitively against
  SB> "kernel".


from perlre:

	(?imsx-imsx)
               One or more embedded pattern-match modifiers.
               This is particularly useful for patterns that are
               specified in a table somewhere, some of which want
               to be case sensitive, and some of which don't.
               The case insensitive ones need to include merely
               (?i) at the front of the pattern.  For example:

                   $pattern = "foobar";
                   if ( /$pattern/i ) { }

                   # more flexible:

                   $pattern = "(?i)foobar";
                   if ( /$pattern/ ) { }

               Letters after - switch modifiers off.

               These modifiers are localized inside an enclosing
               group (if any).  Say,

                   ( (?i) blah ) \s+ \1

               (assuming x modifier, and no i modifier outside of
               this group) will match a repeated (including the
               case!) word blah in any case.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 19 Oct 2000 06:17:00 -0000
From: not-a-real-address@usa.net (those who know me have no need of my name)
Subject: Re: Rijndael in Perl
Message-Id: <sut4esg0qcr3c3@news.supernews.com>

<1eipo5k.cqrn9u17tsqe1N%tony@svanstrom.com> divulged:

>Anyone that knows if Rijndael exists in Perl yet and/or if someone's
>working on it?

ummm.  how would one protect the plaintext?

-- 
okay, have a sig then


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

Date: Thu, 19 Oct 2000 16:12:48 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Search, pad, replace
Message-Id: <slrn8ut0mg.fji.mgjv@martien.heliotrope.home>

On Thu, 19 Oct 2000 02:42:13 GMT,
	Duke Normandin <01031149@3web.net> wrote:

> Again... your frustrations are probably well-founded! Don't reply -- and if 
> you do, don't put anybody down. Stick with issue, and your stature will 
> increase exponentially.

If deja still had their full archive, I'd refer you to the numerous
posts that we've had in the past about this subject. Many people here,
including me, do not believe that silence will make any of the wider
problems with this group go away. You obviously also don't believe that,
or you wouldn't have bothered even getting into this discussion.

FWIW, the OP and I have exchanged email, and hopefully resolved any bad
feelings that came up.

I'll now reset my killfile back to what it was before this thread,
but I will kill this thread itself. I just have better things to do
right now than continue this. None of this ever 

*NO CARRIER*
-- 
Martien Verbruggen              | 
Interactive Media Division      | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd.   | no excuse - Lazarus Long
NSW, Australia                  | 


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

Date: Thu, 19 Oct 2000 05:17:50 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sort Help Needed
Message-Id: <x71yxds934.fsf@home.sysarch.com>

>>>>> "GJ" == Gwyn Judd <tjla@guvfybir.qlaqaf.bet> writes:

  GJ> I was shocked! How could Larry Rosler <lr@hpl.hp.com>
  GJ> say such a terrible thing:
  >> In article <39ED552B.4A01D107@stomp.stomp.tokyo> on Wed, 18 Oct 2000 
  >> 00:45:47 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...

  >>> @New_Array = map { $_ -> [0] } sort { $a -> [1] <=> $b -> [1] }
  >>> map { [$_, (split /¦/) [1]] } @Array;
  >> 
  >> That is not a proper date sort, as one would discover in a few months.

  GJ> What happens in a few months and how will the sort fail?

you cut out moronzilla's incorrect and unwanted editing of the input
data. 

>           teamesteem ¦10252000 andy      bee

the year is after the month and date so when 2001 comes along,
moronzilla will be proven a moron again.

you sort dates first by year then by month and then by date. 

in a single date string key that means you would want 20001025 for the
above date.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 19 Oct 2000 09:12:13 GMT
From: gelshocker@my-deja.com
Subject: string extraction
Message-Id: <8smdta$j2e$1@nnrp1.deja.com>

Hi,

Can anyone help me out please:

How can I extract a substring based on pattern matching.

For example: original string is "aaaaa~bbbbb~~~ccccc~~"

How can I extract aaaaa into one varible, and bbbbb into another? The
Perl Bible has substr defined, but is based on offset and length. In
this case, the length woulb be unknown, but I do know the characters
used to delimit the string and its parts.

Many, many thanks for any advise!!

Regards,
Jason


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 19 Oct 2000 09:39:54 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: string extraction
Message-Id: <slrn8utgdc.28m.bernard.el-hagin@gdndev25.lido-tech>

On Thu, 19 Oct 2000 09:12:13 GMT, gelshocker@my-deja.com
<gelshocker@my-deja.com> wrote:
>Hi,
>
>Can anyone help me out please:
>
>How can I extract a substring based on pattern matching.
>
>For example: original string is "aaaaa~bbbbb~~~ccccc~~"
>
>How can I extract aaaaa into one varible, and bbbbb into another? The
>Perl Bible has substr defined, but is based on offset and length. In
>this case, the length woulb be unknown, but I do know the characters
>used to delimit the string and its parts.

If you know the delimitter use split.

($a, $b, $c) = split /~+/, $input_string;

or, if you don't know how many fields there will be or if there are
many:

@fields = split /~+/, $input_string;

Then loop through @fields and do whatever you want with each element.

For more info:

perldoc -f split

Cheers,
Bernard
--
perl -le'
($B,$e,$r,$n,$a,$r,$d)=q=$B$e$r$n$a$r$d==~m;
\$(.);xg;print$B.$e.$r.$n.$a.$r.$d;'


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

Date: 19 Oct 2000 04:49:16 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: string extraction
Message-Id: <8smg2s$anh$1@provolone.cs.utexas.edu>

In article <8smdta$j2e$1@nnrp1.deja.com>,  <gelshocker@my-deja.com> wrote:
>How can I extract a substring based on pattern matching.
>
>For example: original string is "aaaaa~bbbbb~~~ccccc~~"
>
>How can I extract aaaaa into one varible, and bbbbb into another? The
>Perl Bible has substr defined, but is based on offset and length. In
>this case, the length woulb be unknown, but I do know the characters
>used to delimit the string and its parts.

You want to use split().  Basically,

	@parts = split (/~/, $original_string);

Or, if you want multiple "~" characters to count as a single
delimiter:

	@parts = split (/~+/, $original_string);

"perldoc -f split" for information on the function
itself, and "perldoc perlre" for information on the
regular expressions it uses to match separator patterns.

Hope that helps.

  - Logan


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

Date: Thu, 19 Oct 2000 09:46:48 GMT
From: gelshocker@my-deja.com
Subject: Re: string extraction
Message-Id: <8smfu7$kee$1@nnrp1.deja.com>

Sorry, found it.

I should be looking for 'split' :p

Jason


In article <8smdta$j2e$1@nnrp1.deja.com>,
  gelshocker@my-deja.com wrote:
> Hi,
>
> Can anyone help me out please:
>
> How can I extract a substring based on pattern matching.
>
> For example: original string is "aaaaa~bbbbb~~~ccccc~~"
>
> How can I extract aaaaa into one varible, and bbbbb into another? The
> Perl Bible has substr defined, but is based on offset and length. In
> this case, the length woulb be unknown, but I do know the characters
> used to delimit the string and its parts.
>
> Many, many thanks for any advise!!
>
> Regards,
> Jason
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

--
"Henshin.......V3!!"
Kamen Rider V3 Home Page
http://www.kamenrider.net/riderv3/


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 19 Oct 2000 09:48:18 +0100
From: "W Kemp" <bill.kemp@wire2.com>
Subject: Re: Tele Commute ONLY - PERL - Java - JS - CSS - HTML - DreamWeaver
Message-Id: <971945608.22964.0.nnrp-07.c3ad6974@news.demon.co.uk>

>>     Telecommuter@Law.com
>
>This is a technical newsgroup, imbecile, not a place to dump insulting,
>ignorant tripe.

Why do you think its insulting?
I just think its technically not feasable to use dreamweaver over timbuktu.
And I doubt if people here do much dreamweaver stuff anyway.


These are persistent spammers, who will probably keep on at it, and never
read replies in the newsgroups, so are best ignored.




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

Date: Thu, 19 Oct 2000 00:15:40 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: value exchange of two vars
Message-Id: <0issus4gn2siugvipnmvievqlak7i76t5i@news.supernews.net>

Jeff Pinyan <jeffp@crusoe.net> wrote:

} [posted & mailed]
} 
} On Oct 18, Bernie Cosell said:
} 
} >Jeff Pinyan <jeffp@crusoe.net> wrote:
} >
} >}   ($a,$b) = ($b,$a);
} >} 
} >} Perl evaluates the values of the variables on the RHS (right-hand side) of
} >} the expression, and then assigns them IN PARALLEL to the variables on the
} >} LHS.
} >
} >I don't mean to be picky here, but is this really a correct description?
} >'in parallel' is nice to say but not my understanding of it all [and
} >indeed, it is not really 'parallel' in the sense of languages and
} >processing environments that can _really_ do things in parallel].
} 
} By "in parallel", I meant that it's NOT doing:
} 
}   $a = $b;
}   $b = $a;
} 
} But rather setting $a and $b to the values of $b and $a AS THEY WERE.  It
} is more correct to explain this as a parallel action, than a series
} action.

Well, I understand [as do we all, I suspect] what you meant [and it is,
indeed, the term that most folk use when describing this idiom], but the
fact is twofold:
  1) it *isn't* "parallel" [not for anyone who has actually used a system
     capable of doing things in parallel]
  2) it, IMO, hides the important thing that the person-asking needs to
     learn.  Memorizing this idiom as a "parallel copy" isn't, IMO, the
     right thing...  learning about how Perl handles lvalues [which makes
     the idiom basically obvious] is, again, IMO, the better strategy.

} >  ($a, $b, $c, $d) = ($d, $c, $a, $b)
} >does slightly more complicated permutation of the values "in parallel" [sic
} >:o)] using the same idea...
} 
} To my best understanding, Perl pushes the values of $d, $c, $a, and $b
} onto the stack, and then reads them off one at a time, and stores them in
} $a, $b, $c, and $d.  "Stack" might not be the proper term, since I think
} that implies a last-in, first-out (LIFO) approach.  This is more of a
} queue, I guess.

Is it actually a queue at all?  Is this somehow optimized and 'magic'ed or
does it do it the vanilla way: the RHS says "construct a list consisting of
the values of THESE four elements".  And then you do a simple
list-assignment of that list to the LHS [that has had its interior lvalues
preserved].  It is no more or less parallel than any other list-context
assignment, right?  That is, if you were explaining to someone about how
Perl handles:
     @array = ($a , $b, $c)
would you actually say that it assigns the three variables to the elements
of the array "in parallel"?  [and indeed, does Perl evaluate the RHS in a
different way than it would if it had 
  (lvalue,lvalue,lvalue) = $a, $b, $c;

and FURTHER indeed, does it actually try to optimize and notice if the
lvalues on the LHS are the same as some/all of the rvalues on the RHS?]

More important, consider:
    ($a{x}, $a{y}) = (something, something)
If this is actually a parallel assignment, then if %a is actually tied to a
database you'll need to know that --- if it is actually a sequential,
left-to-right assignment, then you'll know that record 'x' will be updated
before record 'y'.  Talking "parallel" just makes things confusing, no?
Understanding Perl's handling of lvalues is [IMO] tricky enough without
this kind of unnecessary obscuration...


Again: I apologize for seeming to single you out on terminology that is
pretty much SOP.  I just took this opportunity to bring up this general
issue: the casual use of "parallel" in this context has always rankled me a
bit [yes, I've actually worked on computers that *can* do array operations
in parallel and on multiprocessor systems where "parallel" means *REALLY*
in parallel [and you have to worry about data integrity, locking,
synchronizing, etc]...].  And I realized that once I (mostly) understood
and internalized Perl's handling of lvalues, it was clear that this 'swap
variables' thing wasn't all that tricky... it only appeared tricky if you
*DIDN"T* understand how lvalues work.. so instead of explaining it to folk
as an idiom [and CERTAINLY not saying "parallel"], I just take the
opportunity to point out how that makes clever use of Perl's VERY
cute/fancy lvalue handling...

  /bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Thu, 19 Oct 2000 07:46:18 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: value exchange of two vars
Message-Id: <lc9tusk16rlr0ivhrk113aktfq1gomssok@4ax.com>

Jeff Pinyan wrote:

>>}   ($a,$b) = ($b,$a);

>By "in parallel", I meant that it's NOT doing:
>
>  $a = $b;
>  $b = $a;
>
>But rather setting $a and $b to the values of $b and $a AS THEY WERE.

If you come to think of it, it's actually strange that it works at all.
Look at this, for example:

	$a = 10;
	($x, $y) = ($a, $a++);
	print "\$a is $x, \$a postincremented is $y\n";
-->
	$a is 11, $a postincremented is 10

Even though the code on the RHS is executed from left to right, the
value of previously calculated values can still be changed -- in this
case, because ($a) returns that variable by referece: change the
original, and this "copy" will change with it.

Now, if you do

	($a, $b) = ($b, $a);

Both $a and $b are passed by reference. And if assignment happens from
left top right, first $a then $b, then it's strange that the assignment
to $a doesn't modify the value to be assigned to $b.

Is this a serious case of DWIM?

-- 
	Bart.


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

Date: Thu, 19 Oct 2000 08:55:45 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: weird print behaviorr
Message-Id: <39EE9AF0.C599F431@schaffhausen.de>

Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------29E08F4B0C2F5F8EFE6071A1
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

nobull@mail.com schrieb:
> 
> Malte Ubl <ubl@schaffhausen.de> writes:
> 
> > print "someString ", CLASS->lookupSomethingInTheDatabase(), " aString";
> >
> > The output one would expect would be:
> > someString someData aString
> >
> > But this happens:
> > someData someString aString
> 
> I expect CLASS->lookupSomethingInTheDatabase is print()ing someData
> rather than return()ing it.

Yup, got that already.

Thanx!
--------------29E08F4B0C2F5F8EFE6071A1
Content-Type: text/x-vcard; charset=us-ascii;
 name="ubl.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Visitenkarte fŸr Malte Ubl
Content-Disposition: attachment;
 filename="ubl.vcf"

begin:vcard 
n:Ubl;Malte
tel;cell:+49 173 9237521
tel;fax:+49 4121 472938
tel;home:+49 4121 438297
tel;work:+49 4121 472964
x-mozilla-html:FALSE
url:http://www.schaffhausen.de
org:Schaffhausen | Interactive
adr:;;Daimlerstrasse 17;Elmshorn;;25337;Germany
version:2.1
email;internet:ubl@schaffhausen.de
title:Developer for web-based applications
x-mozilla-cpt:;1
fn:Malte Ubl
end:vcard

--------------29E08F4B0C2F5F8EFE6071A1--



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

Date: 18 Oct 2000 21:48:09 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: whence $0
Message-Id: <m1snptsagm.fsf@halfdome.holdit.com>

>>>>> "Peter" == Peter McMorran <mcmorran@visi.net> writes:

>> So $0 contains the name of the file containing the Perl script
>> currently being executed, but where can I find the path to said
>> file?

Peter> A little clarification is in order here. On Unix-like systems, if
Peter> you have a script called fred.pl, and run it from the prompt as

Peter> % fred.pl 

Peter> then $0 contains either the simple name of the file, if it was
Peter> run from the current directory, or the expanded path to the file
Peter> consisting of the name prefixed by the entry in $path that was
Peter> used to find it.

Or something else entirely.  Remember, $0 is trivial to spoof... Perl
even gives you the tools to do it:

   system { $what_I_want_dollar_0_to_say } $program, @args;

It just happens that the shells *usually* put the program name
in $0.  But that's just a *usually*.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4661
**************************************


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