[12805] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 215 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 21 17:07:31 1999

Date: Wed, 21 Jul 1999 14:05:13 -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           Wed, 21 Jul 1999     Volume: 9 Number: 215

Today's topics:
        ****Perl tutorials!!!!**** (IlIIIIIIII)
    Re: Ab: Locking files in win95 (elephant)
    Re: example for HTML SELECT MULTIPLE <sklivvz@tiscalinet.it>
    Re: Fetching HTTP documents <David.Hiskiyahu@alcatel.be>
    Re: finding last created files in a directory (Larry Rosler)
    Re: FORMS parsing <mail@netron.de>
    Re: Fun with Net:NNTP (I R A Darth Aggie)
    Re: Fun with Net:NNTP <dgreer@websightsolutions.com>
    Re: HELP: Faster alternative of substr()? <sklivvz@tiscalinet.it>
    Re: How to divide output paga to <1> <2> <3> ... ? <factory@factory.co.kr>
    Re: How to get the names of the running processes <swiftkid@bigfoot.com>
    Re: How to get the names of the running processes (elephant)
    Re: How to give Passwords on STDIN (elephant)
        Insecure $ENV{PATH} while running setuid <kelvin.tu@rnb.com>
    Re: Kinda FORK <mail@netron.de>
    Re: lexical $_ with threads question? <derek_sherlock@hp.com>
        macros in perl? mda@discerning.com
    Re: newbie question: how put files from dir in array (Walter Tice USG)
    Re: newbie question: how put files from dir in array <mikecard@my-deja.com>
    Re: Perl can't do ">>filename" -- geesh! (Larry Rosler)
    Re: Perl can't do ">>filename" -- geesh! (John Borwick)
    Re: Perl on IIS <shivan@is.hhsys.org>
    Re: pipe "|" functionality: ksh can easily do, perl can <d-edwards@uchicago.edu>
        Q: simple glob <m-andric@students.uiuc.edu>
    Re: Question about POST (multipart/form-data) requests <swiftkid@bigfoot.com>
    Re: regular Expression (Tad McClellan)
    Re: regular Expression <bivey@teamdev.com>
        regular expressions with DBI and SQL <khowe@performance-net.com>
    Re: regular expressions with DBI and SQL <swiftkid@bigfoot.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: 21 Jul 1999 19:50:51 GMT
From: iliiiiiiii@aol.com (IlIIIIIIII)
Subject: ****Perl tutorials!!!!****
Message-Id: <19990721155051.26797.00000058@ng-bh1.aol.com>

at http://devlib.cjb.net, a great web site


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

Date: Thu, 22 Jul 1999 06:45:13 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: Ab: Locking files in win95
Message-Id: <MPG.1200dc653b1ab4a3989b62@news-server>

arpith@hotmail.com writes ..
>Still, staying with locking files in '95.
>flock() doesn't work and the other alternative is using lock files.

and that's where the expertise of this PERL newsgroup ends

>Isn't there some external program like share.exe or something to take
>care of this work ?

who knows .. we're not Windows95 OS experts

followups guessed at and set

-- 
 jason - remove all hyphens for email reply -


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

Date: Wed, 21 Jul 1999 22:37:32 +0200
From: "Marco Cecconi" <sklivvz@tiscalinet.it>
Subject: Re: example for HTML SELECT MULTIPLE
Message-Id: <7n5aus$85j$1@aquila.tiscalinet.it>

use CGI ":standard";
print header;
foreach (param('BanList')) {
    print "$_<br>\n";
}



M.A. Henderson wrote in message <3795D2C6.3538F03D@esn.net>...
>Could someone give an example how to retrieve the multiple selections in
>this:
>
>print '<SELECT MULTIPLE NAME="BanList" SIZE="5">'."\n" ;
>      foreach my $elem (@banarray) {
>         print "<OPTION VALUE=>$elem </OPTION>\n" ;
>       }
>
>




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

Date: Wed, 21 Jul 1999 20:38:09 +0200
From: David Hiskiyahu <David.Hiskiyahu@alcatel.be>
To: Spike, White
Subject: Re: Fetching HTTP documents
Message-Id: <37961391.71D11D1F@alcatel.be>

When using `wget` make sure that you use the '-q' (quiet)
option, otherwise error messages will make your browser
give an error for the whole output of the script.

Use for example:

$myurl = "http://www.foo.bar/index.html";
$wget_response = `wget -q -O /mydir/myfile $myurl`;

Do not expect 'wget' to just give the file in its
return value - it will insist to put it in a file.

If anyone out there knows how to get the contents
of http page directly into a variable, without going
through a file, please reply (preferably directly by
email).

David.

Spike White wrote:
> 
> Or pull down and compile wget, which is a
> public domain utility that grabs URLs.
> 
> Then do something like:
>    $url = `wget http://www.foo.bar/index.html`
 ...


-- 
***   David Hiskiyahu, Alcatel SSD, 1 Fr.Wellesplein,  Antwerp  ***
***    Phone/Fax: +32 3 240 7965/9820, private +32 3 225 2712   ***


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

Date: Wed, 21 Jul 1999 11:32:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: finding last created files in a directory
Message-Id: <MPG.11ffb1f63386bf23989d10@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7n510r$2s5$1@nnrp1.deja.com> on Wed, 21 Jul 1999 17:46:07 
GMT, stef790@my-deja.com <stef790@my-deja.com> says...
> I would like to be able to read in a variable the
> names of the five last created files in a given
> directory containing hundreds of files, based on
> the files creation dates.

Deficient operating systems (of the Unix variety) store no information 
on file creation dates.  Too bad.  You can get last-accessed, last-
modified, or 'last-inode-changed' dates, where an 'inode' is an artifact 
of those file systems that contains some information about a file.

> What would be the most efficient strategy? Is
> there a way to avoid to stat all the files?

Assuming the 'changed' date is what you want, you must stat all the 
files (or use the '-C' operator, which does the same thing).  Then sort 
by it and slice the extreme five that you want from the sorted list.  Be 
sure to use a sorting method that stats each file once only, not in the 
sortsub. 

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


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

Date: Wed, 21 Jul 1999 19:59:15 +0200
From: Mike Eiringhaus <mail@netron.de>
Subject: Re: FORMS parsing
Message-Id: <37960A73.6C471D7D@netron.de>

assistmanager@my-deja.com wrote:
> 
> If someone could help me with the following that would be great..
> 
> i'd like to read in an html file and if it has a form in it..  out put
> the action and all the name/values.. in some way that could be usefull
> if i was to make something that would easily allow automated submission.

Programming Perl, 2nd edition
1996 O'Reilly & Associates, Inc.

Hope I could help you ;-)
Mike Eiringhaus


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

Date: 21 Jul 1999 18:01:03 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: Fun with Net:NNTP
Message-Id: <slrn7pc2r7.hsl.fl_aggie@thepentagon.com>

On Wed, 21 Jul 1999 11:20:24 -0500, Darren greer
<dgreer@websightsolutions.com>, in
<3795F348.458C8CE@websightsolutions.com> wrote:

+ I have been unable to find any documentation that gives me the details
+ that I have been looking for.

Even 'perldoc Net::NNTP'???

James


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

Date: Wed, 21 Jul 1999 13:27:08 -0500
From: Darren greer <dgreer@websightsolutions.com>
Subject: Re: Fun with Net:NNTP
Message-Id: <379610FC.6696BA21@websightsolutions.com>

I R A Darth Aggie wrote:

> On Wed, 21 Jul 1999 11:20:24 -0500, Darren greer
> <dgreer@websightsolutions.com>, in
> <3795F348.458C8CE@websightsolutions.com> wrote:
>
> + I have been unable to find any documentation that gives me the details
> + that I have been looking for.
>
> Even 'perldoc Net::NNTP'???
>
> James

If you can make out exactly how to post to newsgroups using that
documentation, you can read much deeper into than I can.  No where in there
does it say the format that MESSAGE should be in.  Which I think is my main
problem (looking at my code).  Im just looking for clarification in that
respect.

Darren




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

Date: Wed, 21 Jul 1999 22:46:42 +0200
From: "Marco Cecconi" <sklivvz@tiscalinet.it>
Subject: Re: HELP: Faster alternative of substr()?
Message-Id: <7n5bf8$8v7$1@aquila.tiscalinet.it>

I think this is much faster... hope it helps!

BEGIN {
    $EncryptionArray2='';
    for ($i=0; $i<255; $i++) {
        $EncryptionArray2.=chr($i)
    }
}
 .
 .
 .
$SrcArray=~tr/$EncryptionArray2/$EncryptionArray/;

Marco Cecconi
Inferentia S.p.A.
perl -e 'use Standard::Disclaimer;'

hassanov@my-deja.com wrote in message <7n4ife$s5g$1@nnrp1.deja.com>...
>Regarding huge arrays, is there any better (faster) way to do the
>following:
> for($i=0;$i<length($SrcArray);$i++)
> {
> $ord1=ord(substr($SrcArray, $i, 1));
> $ord2=ord(substr($EncryptionArray, $i, 1));
> substr($DstArray, $i, 1)=chr( $ord1 + ord2 );
> }
>
>Thanks
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.




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

Date: Thu, 22 Jul 1999 03:18:54 +0900
From: "Yeong Mo/Director Hana co." <factory@factory.co.kr>
Subject: Re: How to divide output paga to <1> <2> <3> ... ?
Message-Id: <7n52cu$pq1$1@news1.kornet.net>

Anybody wiil help me ?

I have a simple script getting search result to use my own flat db file.
I know how to display all of lines at one page.
I just want to devide the result by page by page.
And it is better if I know the way how to search from selection option for
each fields.

Like bellow from html page;
<table border=0 cellpadding=8 bgcolor=50A0FF><tr align=center>

<form method=get action="http://anydomain.com/penpal.cgi">
<td><FONT SIZE=-1>
<select name=live>
<option selected>all areas
<option>area 1
<option>area 2<option>area 3<option>area 4<option>other area
</select>

<select name=age><option selected>all ages<option>under
10<option>10~15<option>15~20
<option>20~25<option>25~30<option>30~35<option>35~40
<option>40~50<option>50~60<option>over 60</select>

<select name=job><option selected>all jobs<option>job1<option>job2
<option>job3<option>job4<option>job5<option>others</select>

<select name=status><option selected>all<option>married<option>not
married<option>divorced</select>
<select name=sex><option>male<option selected>female</select></font></td>
<td><font size=-1><input type=submit value="  search
"></FONT></td><td></form></td></tr>
</table>
Yeong Mo/Director Hana co. ÀÌ(°¡) <7n4r1s$4ra$1@news1.kornet.net> ¸Þ½ÃÁö¿¡¼­
ÀÛ¼ºÇÏ¿´½À´Ï´Ù...
>Dear,
>
>First,  How to divide output paga to <1> <2> <3> ... as a search result of
>flat db searching  ?
>
>
>Second,  I am looking for free flat db search script
>which has $ex0, $ex1, $ex2 variables for matching by select option.
>If you have this please let me get it.
>
>Thanks in advance.
>
>




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

Date: Wed, 21 Jul 1999 23:26:27 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: How to get the names of the running processes
Message-Id: <7n66mi$elf4@news.cyber.net.pk>

osman durrani <osman@focomedia.de> wrote in message
news:3796005f.0@news.arcor-ip.de...
: Hi,
:  Does anyone know how i can get the complete list of the currently running
: processes (if possible with pid no)  on my computer .
: I am using Perl 5 under NT.

Check out Win32::* modules. Or grab a "ps" port for Win32. (ps comes with
CygWin32)





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

Date: Thu, 22 Jul 1999 06:39:12 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: How to get the names of the running processes
Message-Id: <MPG.1200dafa1f60d12a989b61@news-server>

Faisal Nasim writes ..
>osman durrani <osman@focomedia.de> wrote in message
>news:3796005f.0@news.arcor-ip.de...
>: Hi,
>:  Does anyone know how i can get the complete list of the currently running
>: processes (if possible with pid no)  on my computer .
>: I am using Perl 5 under NT.
>
>Check out Win32::* modules. Or grab a "ps" port for Win32. (ps comes with
>CygWin32)

or Microsoft's tlist or pulist utilities which come with the NT Resource 
Kit

-- 
 jason - remove all hyphens for email reply -


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

Date: Thu, 22 Jul 1999 06:54:54 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: How to give Passwords on STDIN
Message-Id: <MPG.1200dea585a2d9e4989b63@news-server>

osman durrani writes ..
>actually i wanted to know how can i get a password but not have the
>passwaord visible on the STDIN.
>This way you see the actuall password ,so it is not very good if you want to
>keep your password secrete from prying eyes.

tell the user to cover the screen ?

there's an example of a non-Term::ReadKey password thingy in the perlfunc 
document in the section on the 'crypt' command using the stty command 
(obviously this does not port to NT unless you find an stty port *8^)

-- 
 jason - remove all hyphens for email reply -


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

Date: Wed, 21 Jul 1999 14:22:24 -0400
From: Kelvin Tu <kelvin.tu@rnb.com>
Subject: Insecure $ENV{PATH} while running setuid
Message-Id: <37960FE0.D40DAE00@rnb.com>

Hi All

I have encountered the problem  by executing the following command in
perl script while using setuid.

print `ls -l *_out.csv`;

The error message is :

Insecure $ENV{PATH} while running setuid at KT.pl line 3.

It looks like that perl sees setuid as an insecure operation and tried
to prevent it.  Any one knows how to turn this check off.

Thanks
Kelvin



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

Date: Wed, 21 Jul 1999 20:40:06 +0200
From: Mike Eiringhaus <mail@netron.de>
Subject: Re: Kinda FORK
Message-Id: <37961406.DE155986@netron.de>

GiN wrote:

> so this will do:        while (<S>) {
>                                           function($line);
>                                     }
> 
> but function() has to be finished to read another line.
> how can i read another line and do a function($line) without waiting
> for function($line) to finish?

With a child process.

while (<S>) {
FORK: {
  if ($pid = fork) {
    push (@pids, $pid);
  } elsif (defined $pid) {
    function($line);
    exit;
  } elsif ($! =~ /No more process/) {
    sleep 5;
    redo FORK;
  } else {
    die "Cannot execute fork: $!\n";
  }
}
# Wait for all Processes. Can executed later
foreach (@pids) {
  waitpid $_, 0;
}


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

Date: Wed, 21 Jul 1999 13:27:47 -0600
From: Derek Sherlock <derek_sherlock@hp.com>
Subject: Re: lexical $_ with threads question?
Message-Id: <37961F33.938B75D@hp.com>


Dan,

Thanks for patiently quiding me through all this stuff!

I now understand the current implimentation, and look forward to the
day when I can un-learn it all and learn about the per-thread global
implimentation instead!

Derek.


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

Date: Wed, 21 Jul 1999 18:03:46 GMT
From: mda@discerning.com
Subject: macros in perl?
Message-Id: <7n521o$3a5$1@nnrp1.deja.com>

(sorry if this is duplicate. frigging dejanews....)

This must be a faq but I can't find it.

How does one write a "macro" in perl -- a function whose
arguments are not evaluated before invoking the caller.

This would be useful for a debug/trace function (the only
case i use macros in C):
  debuglog "something expensive: ", expensive();
so i don't have to sprinkle "if $debug_on" everywhere, nor
worry about expensive() being called needlessly.

-mda


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 21 Jul 1999 18:02:30 GMT
From: tice@hunch.zk3.dec.com (Walter Tice USG)
Subject: Re: newbie question: how put files from dir in array
Message-Id: <7n51vm$tds@zk2nws.zko.dec.com>

<snip>

>Is there any _particular_ reason why no one recommended:

>@files = glob("$DIR/$PATTERN");

>??? I use this especially if I want a certain pattern, say
>$PATTERN="*.[Hh][Tt][Mm]*"; then do a foreach $file (@files)...

>Cheers,
>Fil.

I used to use glob, but when I came across a case of having to extract
all fillnames from two dirs of 70K plus files, I found out this
works a lot faster:

    opendir THISDIR, $AT || die "THISDIR func died $AT\n";
    @T1 = grep !/^\.\.?$/, readdir THISDIR;     # read 'atext'
    closedir THISDIR;

W


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

Date: Wed, 21 Jul 1999 19:56:43 GMT
From: mike cardeiro <mikecard@my-deja.com>
Subject: Re: newbie question: how put files from dir in array
Message-Id: <7n58li$6cn$1@nnrp1.deja.com>

In article <7mje4p$3o22@news.cyber.net.pk>,
  "Faisal Nasim" <swiftkid@bigfoot.com> wrote:

> opendir MYDIR , "/etc/yourdir" or die "error: $!";
>     @files = readdir MYDIR;
> close MYDIR;
>
you'll probably also want to:
shift @files;
shift @files;

since the first to entries will be . and .. which you probably don't
want in your array.

mike cardeiro


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 21 Jul 1999 11:23:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl can't do ">>filename" -- geesh!
Message-Id: <MPG.11ffafec47e39de3989d0f@nntp.hpl.hp.com>

In article <3795fcc0.2683690@news.skynet.be> on Wed, 21 Jul 1999 
17:08:29 GMT, Bart Lateur <bart.lateur@skynet.be> says...
 ...
> 	use Fcntl qw(:flock);
> 	open(LOG,">>logfile"); # or die...
> 	flock LOG, LOCK_EX; # wait for exclusive access
> 	seek LOG, 2, 0; # append

We have been here before.  Though harmless, this seek is unnecessary.  
The C library and system interfaces guarantee that *any* write to a file 
opened for append will go to the current end of the file.

  > 	print LOG "Well this is $$ talking\n";
> 	close LOG; # This also unlocks it
> 
> I'm pretty sure this MUST be somewhere in the docs, as I sure as
> anything did not invent this piece of code myself.

I would look in deja.com, if I cared.

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


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

Date: Wed, 21 Jul 1999 19:49:34 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: Perl can't do ">>filename" -- geesh!
Message-Id: <379c229b.199917055@newshost.unx.sas.com>

On Wed, 21 Jul 1999 16:50:51 GMT, wallewek@kmsi.net wrote:

>In just about any normal Unix scripting language, not to mention DOS
>Batch, it is possible to redirect and append the output of any command
>to any arbitrary log file. I find this extremely useful and convenient
>for logging events that occur during user logins.
>
>From what I can see, the only way to do this with perl is clunky -- I
>have to redirect the output with a separate command, and turn it off
>afterward again with another separate command.
>
>As I'm planning to have a lot of users running the same script at the
>same time, appending to the same log file, there is also the concern
>about simultaneous write access.  Using ">>filename" is about as close
>to an atomic operations as I'm likely to get.
>
>Am I missing something, or is this something perl just doesn't do
>well?
>
>/kenw
>Ken Wallewein
>Calgary, Alberta
>kenw@kmsi.net

Well I wrote an append function:

sub append { $"=sys; *e=*_; @x=qw<open write >; $\="\n"; $x[@x+1]=
$_[0]; s%%"/$x[3]/&&die;@x[2,0](Q,$x[3],265);@x[2,1](Q,\$e.
chr(10),length(\$e)+1)"%ee while $e=shift }

use as: &append('filename', "line1", "line2");

it adds newlines to each argument.  make sure not to name your file
'log' or anything else that is an actual perl function though.

yrs,
-- 
John Borwick


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

Date: Wed, 21 Jul 1999 14:37:01 -0500
From: Shiva Nadarajah <shivan@is.hhsys.org>
To: Bennett <bennett_j@yahoo.com>
Subject: Re: Perl on IIS
Message-Id: <3796215D.4B124DDC@is.hhsys.org>

Thats wierd that he is "scared" to install an interpreter. I understand
that he is relucatnat to install extra software on a production box that
doesnt really need it.

If all you need it that the CGI accepts the variables and then sends out
and email then you can use Active Server Pages to do this. This way you
can finish up the job and he can be happy that no additional components
had to be installed on the web server.

Of course SMTP will have to be running on the box for it to be able to
sned out emails.

Best regards,
Shiva

Bennett wrote:
> 
> I need to run a Perl script on a box using IIS 4.0.  The system
> administrator is too scared to install an interpreter.  However, he
> seems to think that I can run the script without having to put perl on
> the server.  I am doubtful that it is possible, but if anyone can help
> me out, I would appreciate it.
> 
> FYI- The script is a generic one that returns the results of form
> fields via e-mail.  With Perl I can only use one script for all 15
> forms.  If there is another way to do this without writing a separate
> script for each form and not using Perl, I would appreciate that advice
> as well.
> 
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.


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

Date: Wed, 21 Jul 1999 20:01:27 GMT
From: Darrin Edwards <d-edwards@uchicago.edu>
Subject: Re: pipe "|" functionality: ksh can easily do, perl can hardly do?
Message-Id: <tgvhbdn560.fsf@noise.bsd.uchicago.edu>

[post being responded to was also on comp.unix.shell, I won't send
this there since I don't read that group and fear the following is
off-topic there...]

mwang@tech.cicg.ml.com (Michael Wang) writes:

> For differnet situations, I want to generate two LISTS.
> And depending on the existence/order of situation, I want the
> "COMBINATION" of the LISTS, and then I want to traverse the COMBINED LIST.
> I want to do this without having to save anything in @VARIABLES. 
> This is because the LIST maybe LONG, and doing so will use a lot
							     ^ ^^^
> of memory.
  ^^ ^^^^^^
[snip]
> #!/usr/local/bin/perl -w
> 
> use strict;
> 
> my $i;
> my $j;
> my @i=();
> my @j=("a", "b");    # @j could be ("a"), ("b"), ("b", "a")
> 
> foreach $j ( do {                   # hope to get either (1..5), (6..10),
>                foreach $i (@j) {    # (1..10), (6..10 1..5) depending @j
>                  if ( $i eq "a" ) {        # generate long list, do not want 
>                    map { $_ } (1 .. 5);    # to put in variable to save 
>                  } else {                  # memory, in each of the if-else
>                    map { $_ } (6 .. 10);   # branch.
>                  }
>                }
>              }
> ) {
>   print $j;
> }
[snip ksh]

Uggh.  When I suggested "foreach var (do{blah}) {}" (without the inner
foreach!) I thought it was ugly and contrived, and now I see how
poorly generalizable it is.  Forget I mentioned it.  My main concern is
that although I believe "foreach my $item (@list)" doesn't need to
make an additional copy of @list (changing $item changes the corresponding
element of @list), I am worried now that the more contortions you go
through, the more chances there are that you'll end up copying _something_.
(The simplest analogy I can think of is how "foreach my $key (keys %hash)"
gives you a copy of the list of keys in addition to the original hash.)

If you don't want to try the "reader" subs thingy I also suggested in
a previous post, maybe you need to invest more time tackling the data
structures side of the problem in addition to the algorithm side.  I
hate how vague that sounds, but I'm still not very sure I understand
where exactly your lists are coming from: in your previous post on
this subject you implied that they could be coming either from a
(big?) hash or a filehandle (pointing to a big file?), and that you
needed to decide which it was at runtime; whereas above you just have
simple lists, which makes the algorithm above look much more
complicated than necessary.  If the lists are already in memory, and
you just don't want any _new_ copies taking up space, then can't you
just pick (at runtime) one of a pair of references pointing to the
lists you want to use?  If they're too big for even a _single_ copy of
such a list (e.g. a filehandle), you might need some kind of sub to do
the reading after all.  Either way, try storing the refs as values in
a hash, with the keys being what you use at runtime to decide where to
read from.  Since I've already afflicted you (and everyone else on the
group :( ) with _two_ ugly ideas, I guess I might as well try a 3rd:

#!/usr/local/bin/perl -w
use strict;

my %things_i_have = (
		     homer => [qw(my baloney has a first name)],
		     marge => [qw(my least nagging voice)],
		     bart  => [qw(my shorts)], #a short list
		     lisa  => [qw(my father is a baboon)]
);

my @things_i_want = qw(lisa bart maggie);

foreach my $thing (@things_i_want) {
    if (ref($things_i_have{$thing}) eq 'ARRAY') {
	foreach my $item (@{$things_i_have{$thing}}) {
	    if ($item eq 'my') {
		$item = uc($item);
	    }
	}
    } else {
	print "hey! i have no $thing!\n";
    }
}

foreach my $list (values %things_i_have) {
    print "a list is now @{$list}\n";
}

__END__

The hash values could be changed to, say, sub refs instead of array
refs (or some other way of pulling in your data: most important, they
do _not_ need to be the same "things" as each other); you'd need a
"smarter" inner loop, but it needn't be more memory intensive (might
be more time intensive, but that's why they call them tradeoffs).

You might also be interested in "How can I convert my shell script to
perl?"  from perlfaq8 (coincidentally -- or maybe not! -- posted today
by Tom Christiansen), which mentions the pipelining issue (but
basically reaches the same conclusion, one should rethink the
algorithm in "native" Perl, rather than struggle to literally
translate an idiom like shell pipes).  On the subject of subs to read
things off a data stream rather than pulling in the whole list at
once, I read a fantastic web page (to which I am sure I was directed
by a posting on this group) on the subject, showing how to implement
such streams (examples were a sub to give you the "next" prime number,
or the next number in a given series, without precalculating a (potentially
infinite) list).  Unfortunately, no matter how hard an object I beat
my head with, I cannot recall even the name of the author, let alone
the location of the page.  (Neither a deja nor a web search helped
me... keywords like "perl stream" or "perl data stream" or "perl prime
number" proved more crippling than fruitful.)  My apologies.

Darrin


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

Date: Wed, 21 Jul 1999 15:53:12 -0500
From: milan andric <m-andric@students.uiuc.edu>
Subject: Q: simple glob
Message-Id: <Pine.GSO.4.10.9907211550190.7084-100000@ux8.cso.uiuc.edu>


What is wrong with the glob statement :

open (DATA, "counties.list");

while ($line=<DATA>){
 chomp ($line);

 if ($line eq "Jo"){$line="jodavies"}
   elsif($line eq "Rock"){$line="rockisla"}
   elsif($line eq "St."){$line="stclair"}

        $new=substr("\L$line",0,8);
        chdir("indexes/$new") || print "can't chdir $!\n";
        if (<*.CSV>){
#it doesn't seem to do anything.. @temp is empty.
        push (@temp, <$new/*.CSV>);}
        chdir ("../../");
}

close(DATA);
print @temp;      


a little stuck...

thanks for any help,
milan



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

Date: Wed, 21 Jul 1999 23:04:22 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: Question about POST (multipart/form-data) requests
Message-Id: <7n65d6$eva3@news.cyber.net.pk>

: I read all docs about LWP and HTTP modules, but found only simple
: example
: at
:
http://www.activestate.com/activeperl/docs/lib/site/HTTP/Request/Common.html
:
:  POST 'http://www.perl.org/survey.cgi',
:             Content_Type => 'form-data',
:             Content      => [ name  => 'Gisle Aas',

<snip>

perldoc lwpcook




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

Date: Wed, 21 Jul 1999 10:38:32 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regular Expression
Message-Id: <81m4n7.jh8.ln@magna.metronet.com>

William (bivey@teamdev.com) wrote:
: Abigail <abigail@delanet.com> wrote in article 
: > I've given the "detect whether an expression has balanced parenthesis"
: > so often to newbie students, and it's so trivial to do in any language,
: > I wouldn't even think 'regex' if I want to solve this.
: > 
: > for (my $i = my $c = 0; $i < length ($str); $i ++) {
: >     my $char = substr ($str, $i, 1);
: >     $c ++ if $char eq '(';
: >     $c -- if $char eq ')';
: >     die "Not balanced" if $c < 0;
: > }
: > die "Not balanced" if $c;
: > 
: > 
: > Extracting the balanced pieces is left as an exercise to the reader.

: I like one-liners myself
: (($str =~ tr/\(//) == ($str =~ tr/\)//) )) or die "Not balanced";
                                           ^
                                           ^

   I like one-liners that:

      1) are syntactically valid

      2) do the right thing


   Having the same number of '(' and ')' characters does not
   mean that they are balanced:

---------------
#!/usr/bin/perl -w
use strict;

my $str = '(balanced) )(not';

(($str =~ tr/\(//) == ($str =~ tr/\)//) ) or die "Not balanced";
---------------


   makes no output...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 21 Jul 1999 20:28:39 GMT
From: "William" <bivey@teamdev.com>
Subject: Re: regular Expression
Message-Id: <01bed3b7$b6b454e0$583c08cf@bill.jump.net>

Tad McClellan <tadmc@metronet.com> wrote in article
<81m4n7.jh8.ln@magna.metronet.com>...
> William (bivey@teamdev.com) wrote:

> : I like one-liners myself
> : (($str =~ tr/\(//) == ($str =~ tr/\)//) )) or die "Not balanced";
>                                            ^
>    I like one-liners that:
> 
>       1) are syntactically valid

Oops, copied too much from the if clause - bad mouse, bad!

> 
>       2) do the right thing
> 
> 
>    Having the same number of '(' and ')' characters does not
>    mean that they are balanced:

Oops, again. Next time I'll wait until I'm awake. -Wm




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

Date: Wed, 21 Jul 1999 15:56:52 -0300
From: "Kevin Howe" <khowe@performance-net.com>
Subject: regular expressions with DBI and SQL
Message-Id: <uEol3.16531$j3.76960@tor-nn1.netcom.ca>

Is it possible to do the equivalent of the following:

select * from [DATABASE] where [THIS FIELD] contains [THIS STRING]

in other words, is it possible to select records based on a field value
containing a substring using DBI/DBD?

Thanks




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

Date: Thu, 22 Jul 1999 00:15:19 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: regular expressions with DBI and SQL
Message-Id: <7n69i7$elf5@news.cyber.net.pk>

: Is it possible to do the equivalent of the following:
:
: select * from [DATABASE] where [THIS FIELD] contains [THIS STRING]
:
: in other words, is it possible to select records based on a field value
: containing a substring using DBI/DBD?

DBI is not a magic! It can perform on anything which is returned by
SQL server. And what you want is provided by all SQL servers...
check out your SQL documentation.

select * from database where myfiled like 'a%'

 .... just an example (I use mysql)





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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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


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