[16696] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4108 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 23 18:05:48 2000

Date: Wed, 23 Aug 2000 15:05:29 -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: <967068328-v9-i4108@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 23 Aug 2000     Volume: 9 Number: 4108

Today's topics:
    Re: @_ as array <tina@streetmail.com>
    Re: @_ as array (Abigail)
    Re: @_ as array (Abigail)
    Re: @ARGV with ( and ) symbols in it (Richard J. Rauenzahn)
    Re: @ARGV with ( and ) symbols in it (Gary E. Ansok)
        A question of idiom [Was: newbie question - dont flame  kent@darwin.eeb.uconn.edu
    Re: A question of idiom [Was: newbie question - dont fl (Greg Bacon)
        Alternate to strtok in perl <desi@byu.edu>
    Re: Alternate to strtok in perl <rmore1@my-deja.com>
    Re: Arrays, hashes wtih braces <lr@hpl.hp.com>
    Re: Assistance needed updating a script <hillr@ugsolutions.com>
    Re: Assistance needed updating a script blindemann@my-deja.com
    Re: Associative arrays <mtaylorlrim@my-deja.com>
    Re: Associative arrays <flavell@mail.cern.ch>
    Re: Beginner/intermediate programmer looking to volunte <care227@attglobal.net>
        date conversion <mail@mail.com>
    Re: date conversion (Greg Bacon)
    Re: Deleteing a file <ren.maddox@tivoli.com>
    Re: Deleting all elements between ZZZ and YYY (Greg Bacon)
    Re: Deleting all elements between ZZZ and YYY <amonotod@netscape.net>
    Re: Deleting all elements between ZZZ and YYY <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Deleting all elements between ZZZ and YYY <ren.maddox@tivoli.com>
    Re: exists() before 5.6 for sub's <tim@ipac.caltech.edu>
        Flipflop matching philip.hibbs@tnt.co.uk
    Re: Flipflop matching (Eric Bohlman)
    Re: Flipflop matching <sp00fD@yahoo.com>
    Re: Flipflop matching <uri@sysarch.com>
        free online CGI/Perl courses <yuliang@home.com>
        getting HTML pages with javascripts inside using perl? <olegaxenov@my-deja.com>
    Re: help with simple regexp - does my head in (Abigail)
    Re: IO::Socket::INET and $SIG{'ALRM'} (Charles DeRykus)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 23 Aug 2000 18:56:43 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: @_ as array
Message-Id: <8o16pa$9oj46$14@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On Wed, 23 Aug 2000 19:23:10 +0600,
> 	Konstantin Stupnik <skv@iis.nsk.su> wrote:
>> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
>> news:slrn8q7ehk.5ap.mgjv@martien.heliotrope.home...
>> >

>> > > or:
>> > > shift;
>> > > my $wanted=shift;
>> >
>> > That will get $_[0] in $wanted, and make @_ one element shorter. That
>> > was clearly not what the OP was asking for.
>> No.
>> The code is:
>> shift;
>> my $wanted=shift;

> I swear I read your original code a few times to find that first shift,
> because I knew it had to be there for this to be correct, and I just did
> _not_ see it. I must be getting old or something like that...

i didn't see it, either. or I actually saw it, but I thought
it was like

or:
do it with shift;
my $wanted= shift;

i didn't assume that "shift;" was already a code line.

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: 23 Aug 2000 19:25:25 GMT
From: abigail@foad.org (Abigail)
Subject: Re: @_ as array
Message-Id: <slrn8q897q.tj3.abigail@alexandra.foad.org>

LecturaX Porodum (haak12@remove.ie.hva.nl) wrote on MMDXLVIII September
MCMXCIII in <URL:news:39a25f6c$0$27096$503c8c87@>:
## Hi,
## 
## How can I best achieve to retrieve the second element (element 1) from @_?
## 
## I get a warning when I do @_[1], but I imagine $_[1] wouldn't work either,
## as $_ is a reserved variable as well.


Huh? $_ [1] has absolutely nothing to do with $_.

Why didn't you spend 20 seconds and tried it out, instead of posting to
Usenet?


Abigail
-- 
BEGIN {$^H {q} = sub {$_ [1] =~ y/S-ZA-IK-O/q-tc-fe-m/d; $_ [1]}; $^H = 0x28100}
print "Just another PYTHON hacker\n";


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

Date: 23 Aug 2000 19:28:04 GMT
From: abigail@foad.org (Abigail)
Subject: Re: @_ as array
Message-Id: <slrn8q89cp.tj3.abigail@alexandra.foad.org>

Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMDXLIX September
MCMXCIII in <URL:news:slrn8q7h9t.5ap.mgjv@martien.heliotrope.home>:
"" On Wed, 23 Aug 2000 19:23:10 +0600,
"" 	Konstantin Stupnik <skv@iis.nsk.su> wrote:
"" > No.
"" > The code is:
"" > shift;
"" > my $wanted=shift;
"" 
"" I swear I read your original code a few times to find that first shift,
"" because I knew it had to be there for this to be correct, and I just did
"" _not_ see it. I must be getting old or something like that...

Yeah, he should have written it as:

    my $wanted = shift, shift;

(And using indent and/or a blank line to separate code from text would
help too).

Abigail
-- 
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();


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

Date: 23 Aug 2000 18:33:27 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: @ARGV with ( and ) symbols in it
Message-Id: <967055606.7495@hpvablab.cup.hp.com>

"Graham Wood" <graham.wood@iona.com> writes:
>I'm attempting to write a script that will accept OS/390 dataset names and
>members thereof as input.  The command line will look like:
>
>process.pl GWOOD.UTIL.JCL(STARTUP)
>
>Sadly perl is complaining that it is getting a "(" where it was expecting a
>newline.

Actually, it's possible that your shell is complaining.  Can you show us
the exact error message?  

>Can anyone point me at the docs that will explain how to fool perl into
>accepting "(" and ")" as valid parts of a command line argument?

Perl shouldn't care -- What your program does with the argument might,
though.

Rich
-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: 23 Aug 2000 20:38:17 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: @ARGV with ( and ) symbols in it
Message-Id: <8o1cnp$240@gap.cco.caltech.edu>

In article <8o0tt8$cjt$1@bvweb.iona.com>,
Graham Wood <graham.wood@iona.com> wrote:
>I'm attempting to write a script that will accept OS/390 dataset names and
>members thereof as input.  The command line will look like:
>
>process.pl GWOOD.UTIL.JCL(STARTUP)
>
>Sadly perl is complaining that it is getting a "(" where it was expecting a
>newline.
>
>Can anyone point me at the docs that will explain how to fool perl into
>accepting "(" and ")" as valid parts of a command line argument?

This sounds like it's more of an issue with your shell than with Perl.
Do you get the same error message if you use echo instead of process.pl?

If this is the case, then you should be able to put the dataset name
in quotes to prevent the special parsing.

-- Gary


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

Date: 23 Aug 2000 13:34:55 -0400
From: kent@darwin.eeb.uconn.edu
Subject: A question of idiom [Was: newbie question - dont flame me]
Message-Id: <uwvh7j2yo.fsf_-_@darwin.eeb.uconn.edu>

>>>>> "Greg" == Greg Bacon <gbacon@HiWAAY.net> writes:

    foreach $displayName (keys %serverList) {
        foreach $uName (keys %{ $serverList{$displayName} }) {
            print $serverList{$displayName}->{$uName}, "\n";
        }
    }

Is there a reason to use $serverList{$displayName}->{$uName} instead
of $serverList{$displayName}{$uName}? The second is more intuitive for
me, but if the first is a standard idiom, I'm willing to change my
preferences.

Kent

-- 
Kent E. Holsinger                kent@darwin.eeb.uconn.edu
                                 http://darwin.eeb.uconn.edu
-- Department of Ecology & Evolutionary Biology          
-- University of Connecticut, U-3043                                       
-- Storrs, CT   06269-3043                                               


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

Date: Wed, 23 Aug 2000 18:44:25 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: A question of idiom [Was: newbie question - dont flame me]
Message-Id: <sq86s92ft91149@corp.supernews.com>

In article <uwvh7j2yo.fsf_-_@darwin.eeb.uconn.edu>,
     <kent@darwin.eeb.uconn.edu> wrote:

: >>>>> "Greg" == Greg Bacon <gbacon@HiWAAY.net> writes:
: 
:     foreach $displayName (keys %serverList) {
:         foreach $uName (keys %{ $serverList{$displayName} }) {
:             print $serverList{$displayName}->{$uName}, "\n";
:         }
:     }
: 
: Is there a reason to use $serverList{$displayName}->{$uName} instead
: of $serverList{$displayName}{$uName}? The second is more intuitive for
: me, but if the first is a standard idiom, I'm willing to change my
: preferences.

There's no reason unless you've been hacking too much C++ lately. :-(

Greg
-- 
When Galileo turned his telescope toward the heavens, and allowed Kepler to
look as well, they found no enchantment or authorization in the stars, only
geometric patterns and equations.  God, it seemed, was less of a moral
philosopher than a master mathematician.  -- Neil Postman


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

Date: Wed, 23 Aug 2000 13:38:16 -0600
From: desi <desi@byu.edu>
Subject: Alternate to strtok in perl
Message-Id: <39A42828.895E11D3@byu.edu>

Is there anything like strtok in perl (ver. 5)
Thanks,
Santosh.



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

Date: Wed, 23 Aug 2000 20:38:14 GMT
From: Rich More <rmore1@my-deja.com>
Subject: Re: Alternate to strtok in perl
Message-Id: <8o1cni$e0n$1@nnrp1.deja.com>

In article <39A42828.895E11D3@byu.edu>,
  desi@byu.edu wrote:
> Is there anything like strtok in perl (ver. 5)
Try
  @tok = split(" ",$var);

For more info:
  perldoc -f split
  perldoc perlfaq4

--
=============================
Richard More
http://www.richmore.com/


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


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

Date: Wed, 23 Aug 2000 11:04:22 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Arrays, hashes wtih braces
Message-Id: <MPG.140db203d2caf94198accc@nntp.hpl.hp.com>

In article <8o1015$ti5$1@nnrp1.deja.com> on Wed, 23 Aug 2000 17:01:39 
GMT, vanis@my-deja.com <vanis@my-deja.com> says...

 ...

> I played around with creating an array using braces..
> 
> @cars = {"corvette", "firebird", "camaro", "pony"}; #which is misfit?
> $cnt = @cars;
> 
> print $cnt;       #prints '1'
> print "@cars";    #prints 'HASH(0x80c118c)'
> print @cars;      #prints 'HASH(0x80c1180)'
> 
> It seems to count the values as a single string..This becomes apparent
> when the same is tried with a hash
> 
> %cars = {"corvette", "firebird", "camaro", "pony"};
> 
> print %cars;     #with warnings turned on, the following is printed
> 
> Odd number of elements in hash list at t.pl line 5 (#1)
> 
> (S) You specified an odd number of elements to a hash list, which is
> odd, because hash lists come in key/value pairs.
> 
> Just curious to know what it's doing, and the difference(s) between
> using braces{} and parentheses()..besides the fact that parentheses are
> what works.. thanks

In the context of an expression, () constructs a list; [] constructs an 
array and a reference to it; {} constructs a hash and a reference to it.

You should have a good read of perldata!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 23 Aug 2000 12:12:47 -0700
From: Ron Hill <hillr@ugsolutions.com>
Subject: Re: Assistance needed updating a script
Message-Id: <39A4222F.6D1FEE7E@ugsolutions.com>




blindemann@my-deja.com wrote:

> I am a rookie just trying to elaborate on a script that is already in
> place using Perl5.  I want to copy  dir1/filename.x to dir2/filename.y
> and delete the original filename.x in dir1.

use File::Copy;
move("/dev1/fileA","/dev2/fileB");




> I also want to include the
> contents of filename.x in a e-mail message that is to be emailed
> automatically to the person who initiated the script.  I have the
> portion of the script that e-mails the user already in place, I just
> need to figure out how to add the contents of the file.

use MIME::Lite;

$msg = new MIME::Lite
                From    =>'me@myhost.com',
                To      =>'you@yourhost.com',
                Cc      =>'some@other.com, some@more.com',
                Subject =>'A message with 2 parts...',
                Type    =>'multipart/mixed';

attach $msg
                Type     =>'TEXT',
                Data     =>"Here's it is";
attach $msg
                Type     =>'image/gif',
                Path     =>'/my/path/to/file/aaa000123.gif',
                Filename =>'whatever.gif';
then do
$str = $msg->as_string;
$str now has what you want to send




>
> Any help would be appreciated.
> Thnxs
> *BOB*
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: Wed, 23 Aug 2000 20:00:12 GMT
From: blindemann@my-deja.com
Subject: Re: Assistance needed updating a script
Message-Id: <8o1afu$b2m$1@nnrp1.deja.com>

That did the trick Ron.  Thnxs for your help.


In article <39A4222F.6D1FEE7E@ugsolutions.com>,
  Ron Hill <hillr@ugsolutions.com> wrote:
>
>
> blindemann@my-deja.com wrote:
>
> > I am a rookie just trying to elaborate on a script that is already
in
> > place using Perl5.  I want to copy  dir1/filename.x to
dir2/filename.y
> > and delete the original filename.x in dir1.
>
> use File::Copy;
> move("/dev1/fileA","/dev2/fileB");
>
> > I also want to include the
> > contents of filename.x in a e-mail message that is to be emailed
> > automatically to the person who initiated the script.  I have the
> > portion of the script that e-mails the user already in place, I just
> > need to figure out how to add the contents of the file.
>
> use MIME::Lite;
>
> $msg = new MIME::Lite
>                 From    =>'me@myhost.com',
>                 To      =>'you@yourhost.com',
>                 Cc      =>'some@other.com, some@more.com',
>                 Subject =>'A message with 2 parts...',
>                 Type    =>'multipart/mixed';
>
> attach $msg
>                 Type     =>'TEXT',
>                 Data     =>"Here's it is";
> attach $msg
>                 Type     =>'image/gif',
>                 Path     =>'/my/path/to/file/aaa000123.gif',
>                 Filename =>'whatever.gif';
> then do
> $str = $msg->as_string;
> $str now has what you want to send
>
> >
> > Any help would be appreciated.
> > Thnxs
> > *BOB*
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
>


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


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

Date: Wed, 23 Aug 2000 18:30:54 GMT
From: Mark <mtaylorlrim@my-deja.com>
Subject: Re: Associative arrays
Message-Id: <8o158v$4cd$1@nnrp1.deja.com>

In article <slrn8q7e5q.5ap.mgjv@martien.heliotrope.home>,
  mgjv@tradingpost.com.au wrote:
> [please, in the future, put your reply after the suitably trimmed text
> you reply to]
>
Well pardon the hell out of me, Mr Moderator

> [reorder post to respect the natural arrow of time]
>
Sorry, I think my time is more valuable than using it to please you. I
have already spent too much time...


> Which defeats the purpose. The poster clearly wanted to find the key
of
> the pair in the hash with the value 0. How are you going to extract
that
> from your solution?
>
I think only the original poster can decide what he needs. I was only
offering something he 'may' have overlooked.

> > %fields = ( "Member ID" => 0, "Forename" => 1, "Surname" = >2 );
>
> And here you already lost the ordering of those pairs. The only order
> that exists is in the values.

As I replied, the order is not preserved.


Does this meet with your specifications?


--
Please reply to this newsgroup as my Deja mail
is used as a spam catcher only!


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


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

Date: Wed, 23 Aug 2000 20:42:56 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Associative arrays
Message-Id: <Pine.HPP.3.95a.1000823204211.24000E-100000@hpplus03.cern.ch>

On Wed, 23 Aug 2000, Mark wrote:

> Sorry, I think my time is more valuable than using it to please you. I

Well, Ive never seen it stated more clearly than that.

A usenet suicide note, no less.



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

Date: Wed, 23 Aug 2000 17:04:41 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Beginner/intermediate programmer looking to volunteer...
Message-Id: <39A43C69.46EA115D@attglobal.net>

Mike Cameron wrote:
> 
> I am a 31 year old Mortgage Banker who has been a hobby programmer for
> several years (VB, JS, HTML, Perl). I have really learned a lot of Perl
> in that time and would like to make a career move.  Problem is I have no
> Computer Science formal education and can't afford to take the pay cut
> that would be required to take an entry level position so I would like
> to start building my programming portfolio via volunteer work part
> time.  Any suggestions on where to start?

In a group with jobs in the name?

> 
> Apologies if this is inappropriate for this forum.

It is, but if you had spent any time posting to any usenet group
in the past, you'd have already known that.  Please post in a
group with *jobs* in the title.  This is a technical discussion
group, not a want ads section.


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

Date: Wed, 23 Aug 2000 15:02:03 -0500
From: GI812 <mail@mail.com>
Subject: date conversion
Message-Id: <39A42DBA.3A708933@mail.com>

Just wondering if anyone would know how to convert a julian date to a
mmdd in perl.



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

Date: Wed, 23 Aug 2000 21:05:35 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: date conversion
Message-Id: <sq8f4vut91150@corp.supernews.com>

In article <39A42DBA.3A708933@mail.com>,
    GI812  <mail@mail.com> wrote:

: Just wondering if anyone would know how to convert a julian date to a
: mmdd in perl.

    use Date::Calc qw/ Add_Delta_Days /;

    # assumes well-formed date like 2000123
    my($year,$jday) = $date =~ /^(\d+)(\d\d\d)$/;

    my($mm,$dd) = ( Add_Delta_Days $year, 1, 1 => $jday-1 )[1,2];

Greg
-- 
I know no method to secure the repeal of bad or obnoxious laws so
effective as their stringent execution.
    -- Ulysses S. Grant


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

Date: 23 Aug 2000 13:21:35 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Deleteing a file
Message-Id: <m3wvh77s9c.fsf@dhcp11-177.support.tivoli.com>

blindemann@my-deja.com writes:

> I am a PERL rookie, so this may be basic for some of you, so I
> apologize in advance if it is!
> I have a scprit I wrote that returns some info to the browser.  After
> this is complete, I want to delete a file that contains data that was
> used in running the script and returned to the browser.  At the very
> end of my scprit after the html is returned to the browser, I added
> unlink myfile.dat;
> 
> Evidently it deletes the file quicker then the HTML fills the page
> because with the unlink at the end of my script, my data doesnt come up
> in the browser.  Is there a way to prevent this?  I tried adding a
> second script to delete the file and calling it in the HTML that is
> returned to the browser, but that doesnt seem to work.  Any suggestions?

Is it possible that the reason your data didn't come up after adding
the unlink is that there was an error?  Did you check the errorlog?
In particular, you probably want:

unlink "myfile.dat";

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 23 Aug 2000 18:47:20 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Deleting all elements between ZZZ and YYY
Message-Id: <sq871onpt9167@corp.supernews.com>

In article <39A40E61.C5B09F43@aw.sgi.com>,
    Ed Braden  <ed@aw.sgi.com> wrote:

: In a text file I would like to remove all lines that exist between all
: the occurances of 'ZZZ' 'YYY'. For example:

    % perl -ne 'print unless /^ZZZ$/ .. /^YYY$/' file

Greg
-- 
Since I was running Windows, I did the normal thing you do when you
encounter problems: I rebooted.
    -- Simson Garfinkel


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

Date: Wed, 23 Aug 2000 18:55:59 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Deleting all elements between ZZZ and YYY
Message-Id: <8o16nj$6fa$1@nnrp1.deja.com>

In article <39A40E61.C5B09F43@aw.sgi.com>,
  Ed Braden <ed@aw.sgi.com> wrote:
> Hi,
>
> In a text file I would like to remove all lines that exist between all
> the occurances of 'ZZZ' 'YYY'. For example:
>
> -----file example-----
> laksdf
> lasdf
> ladf
> TGT
> ZZZ
> want to remove
> these
> lines
> YYY
> lkasdf
> la
> ZZZ
> want
> to remove
> these lines
> YYY
> -----end of file example----
>
> This is easily done in sed since you can specify two addresses and
> perform a delete on all lines between the two addresses but I don't
> see how to do this in Perl.
>

Assumption:  You want the markers gone as well as the unwanted
data.  Well, here's I did it...

#!perl -w
# usage: script.pl BeginPattern EndPattern InFile Outfile
use strict;
unless (@ARGV) { die "Gimme some parameters, man!\n"; }
my $pattern1 = shift;
my $pattern2 = shift;
my $file1 = shift;
my $file2 = shift;
my $status = 0;
unless (open (TEXT, "$file1") ) { die "cant do open: $!\n"; }
unless (open (TEXT2, "> $file2") ) { die "cant do the other open: $!\n";
}
while (<TEXT>){
  chomp;
  if (/$pattern1/) { $status = 1; }
  if ($status != 1) { print TEXT2 "$_\n"; }
  if (/$pattern2/) { $status = 0; }
}
close (TEXT) or die "hey what happened? $!";
close (TEXT2) or die "hey what happened? $!";


> Thanks in advance for any assistance that you can provide.
>
> --Ed
>
>

HTH,
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


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


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

Date: Wed, 23 Aug 2000 11:48:38 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Deleting all elements between ZZZ and YYY
Message-Id: <39A41C86.DC81E3C9@jpl.nasa.gov>

Ed Braden wrote:
> This is easily done in sed since you can specify two addresses and
> perform a delete on all lines between the two addresses but I don't see
> how to do this in Perl.

Take a look at perlop/"Range Operators".

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King


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

Date: 23 Aug 2000 13:53:32 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Deleting all elements between ZZZ and YYY
Message-Id: <m3pumz7qs3.fsf@dhcp11-177.support.tivoli.com>

Ed Braden <ed@aw.sgi.com> writes:

> Hi,
> 
> In a text file I would like to remove all lines that exist between all
> the occurances of 'ZZZ' 'YYY'. For example:

print unless /^ZZZ$/ .. /^YYY$/;

For more information, see perlfaq6: "How can I pull out lines between
two patterns that are themselves on different lines?"

Or just use:

perldoc -q 'between.*lines'

(Using just "between" or just "lines" works, but finds several other FAQs
as well.  "themselves" works, but isn't very intuitive. *grin*)

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 23 Aug 2000 11:49:07 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: exists() before 5.6 for sub's
Message-Id: <39A41CA3.5DE7B3F9@ipac.caltech.edu>

Tim Conrow wrote:
> Jerrad Pierce wrote:
> > Does anybody know of a way to emulate: exists &foo;
> > functionality in a pre 5.6 build?
> sub there {
>   no strict;
>   my $sub = shift;
>   *$sub{CODE};
> }

OK, OK, so 'defined &$foo' is easier. A little dive into the darker parts of
perl is sometimes amusing, isn't it?

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Wed, 23 Aug 2000 19:05:28 GMT
From: philip.hibbs@tnt.co.uk
Subject: Flipflop matching
Message-Id: <8o1798$760$1@nnrp1.deja.com>

I seem to remember reading somewhere that there's a construct in Perl
that behaves something like this: returns false until the pattern
matches, then keeps returning true while the pattern doesn't match, then
returns false again when the pattern matches again, then keeps
returning false until the pattern matches, etc... basically the pattern
is a trigger to reverse the return value.

Am I mad, or is there such an animal?

Phil.


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


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

Date: 23 Aug 2000 19:35:30 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Flipflop matching
Message-Id: <8o1922$81m$2@slb6.atl.mindspring.net>

philip.hibbs@tnt.co.uk wrote:
: I seem to remember reading somewhere that there's a construct in Perl
: that behaves something like this: returns false until the pattern
: matches, then keeps returning true while the pattern doesn't match, then
: returns false again when the pattern matches again, then keeps
: returning false until the pattern matches, etc... basically the pattern
: is a trigger to reverse the return value.
: 
: Am I mad, or is there such an animal?

It's called the range operator.  See perlop for details.



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

Date: Wed, 23 Aug 2000 19:25:50 GMT
From: sp00fD <sp00fD@yahoo.com>
Subject: Re: Flipflop matching
Message-Id: <8o18f4$8ml$1@nnrp1.deja.com>

In article <8o1798$760$1@nnrp1.deja.com>,
  philip.hibbs@tnt.co.uk wrote:
> I seem to remember reading somewhere that there's a construct in Perl
> that behaves something like this: returns false until the pattern
> matches, then keeps returning true while the pattern doesn't match,
then
> returns false again when the pattern matches again, then keeps
> returning false until the pattern matches, etc... basically the
pattern
> is a trigger to reverse the return value.
>
> Am I mad, or is there such an animal?
>
> Phil.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

Sounds like a 100000 ft. overview of how regular expressions work.


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


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

Date: Wed, 23 Aug 2000 19:45:53 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Flipflop matching
Message-Id: <x7em3fu5fz.fsf@home.sysarch.com>

>>>>> "ph" == philip hibbs <philip.hibbs@tnt.co.uk> writes:

  ph> I seem to remember reading somewhere that there's a construct in
  ph> Perl that behaves something like this: returns false until the
  ph> pattern matches, then keeps returning true while the pattern
  ph> doesn't match, then returns false again when the pattern matches
  ph> again, then keeps returning false until the pattern matches,
  ph> etc... basically the pattern is a trigger to reverse the return
         ^^
  ph> value.

  ph> Am I mad, or is there such an animal?

as always the answer is in your question.

this is even more fun than the newbies who ask 'how do i find the length
of a string?'.

perldoc perlop and look for the stuff i marked above.

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: Wed, 23 Aug 2000 21:48:32 GMT
From: yumin liang <yuliang@home.com>
Subject: free online CGI/Perl courses
Message-Id: <39A446B7.7E52459B@home.com>

Hi,

For those who are interested, there are series of free
web based CGI/Perl courses available at

     http://www.freeedu.com/perlcgi

    (Yes. It's free. The website based its revenue income
     from advertisement sponsorship.)

Currently available CGI/Perl courses include:

  CGI/Perl Courses
=======================================
CGI/Perl: CGI/Perl: Building Programs
CGI/Perl: CGI/Perl: Web Applications
CGI/Perl: CGI/Perl: Getting Familiar with Forms
CGI/Perl: CGI/Perl: Interacting With Databases

Thanks,

Yumin
FreeEdu.com




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

Date: Wed, 23 Aug 2000 18:05:44 GMT
From: Oleg <olegaxenov@my-deja.com>
Subject: getting HTML pages with javascripts inside using perl?
Message-Id: <8o13p8$2lv$1@nnrp1.deja.com>

Hello,

I trying to get HTML pages from web server using
  $ua = new LWP::UserAgent;
  $req = HTTP::Request->new(GET => $url);
  $res = $ua->request($req);

and I am experiencing two problems. First, the page has javascript
inside and as a result I am getting error message
-------------------
<body>
 <br><font color=<blink>Note:</blink></font> javascript is required but
is turne
d off on your browser. Click here for information.</a><br>
</html>
----------------------
is the body of document. Is there any way to get actual document?

And second, some of web server's page are protected by Open Market
SecureLink Bridge and use Transact for authorization. And when I am
trying to reach such pages there is a timeout and server forward
request to another server for authorization, but I an getting $res-
>is_success not true. And the question was is is possible to setup some
timeout in such perl script or somehow work around that issue?

Thank you,
Oleg Aksenov


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


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

Date: 23 Aug 2000 19:13:59 GMT
From: abigail@foad.org (Abigail)
Subject: Re: help with simple regexp - does my head in
Message-Id: <slrn8q88ic.tj3.abigail@alexandra.foad.org>

Tina Mueller (tina@streetmail.com) wrote on MMDXLIX September MCMXCIII in
<URL:news:8nv8i3$9nhu1$3@ID-24002.news.cis.dfn.de>:
:: Russ Jones <russ_jones@rac.ray.com> wrote:
:: > Marcel Grunauer wrote:
:: >> 
:: >> But in this case I'd rather use a slice:
:: >> 
:: >>     $attrval = (split("=", $orig_field, 2))[1]
:: 
:: > 	I like this better, too. The [-1] in Mike Stok's post is even MORE
:: > cute.
:: 
:: well, but since you know for sure that the array will
:: contain only 2 elements you should use the 1.
:: i don't know how that -1 is implemented, but I bet
:: it's more work for perl to find out the last
:: element.


Well, yeah, but the difference is insignificant. 


    #!/opt/perl/bin/perl -w

    use strict;

    use Benchmark;

    use vars qw /@a/;

    @a = (1 => 2);

    timethese -10 => {
         1  =>  'my $a = $a [ 1]',
        -1  =>  'my $a = $a [-1]',
    };

    __END__

    Benchmark: running -1, 1, each for at least 10 CPU seconds...
            -1:  9 wallclock secs (10.62 usr + -0.03 sys = 10.59 CPU)
                 @ 445933.52/s (n=4722436)
             1: 14 wallclock secs (10.52 usr +  0.00 sys = 10.52 CPU)
                 @ 529952.57/s (n=5575101)


That's a difference of 355 nanoseconds. The time it takes for light to
do the shortest distance in Olympic track and field.


However, in light of the context, benchmarks show that use of -1 is
fractional faster:


    #!/opt/perl/bin/perl -w

    use strict;

    use Benchmark;

    use vars qw /$orig_field/;

    $orig_field = "monkey=cute";

    timethese -10 => {
         1  =>  'my $attrval = (split "=" => $orig_field, 2) [ 1]',
        -1  =>  'my $attrval = (split "=" => $orig_field, 2) [-1]',
    };

    __END__
    Benchmark: running -1, 1, each for at least 10 CPU seconds...
            -1: 12 wallclock secs (10.52 usr +  0.01 sys = 10.53 CPU)
                 @ 62242.83/s (n=655417)
             1: 12 wallclock secs (10.64 usr +  0.00 sys = 10.64 CPU)
                 @ 61599.34/s (n=655417)


Of course, if such micro-optimization is important to you, you shouldn't
have used Perl.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Wed, 23 Aug 2000 20:35:54 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: IO::Socket::INET and $SIG{'ALRM'}
Message-Id: <FzrIJu.6J1@news.boeing.com>

In article <39A1C003.2DEE7B27@bluewin.ch>,
Basil Achermann  <basil.achermann@bluewin.ch> wrote:
>...
>
>sub connect
>{
>  my($address, $port) = @_;
>
>  eval
>  {
>    $SIG{'ALRM'} = sub { die "timeout" };
>    alarm $DEF_Timeout;
>
>    $rem =IO::Socket::INET->new(PeerAddr =>$address,
>                            PeerPort =>$port,
>                            Proto    =>'tcp');
>
>    alarm 0;
>    $SIG{'ALRM'} = 'DEFAULT';
>  };
>
> ...

>But on the alarm signal, the OS produces an ordinary:
>   [1]   -   Alarm clock             ./abc.pl
>

I think IO::Socket's internal alarm is cancelling your  
own. Try IO::Socket's timeout instead:

     IO::Socket::INET->new( ... , Timeout => $DEF_Timeout, ); 

--
Charles DeRykus


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

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


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