[8335] in Perl-Users-Digest
Perl-Users Digest, Issue: 1952 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 22 21:08:03 1998
Date: Sun, 22 Feb 98 18:00:47 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 22 Feb 1998 Volume: 8 Number: 1952
Today's topics:
Re: A Few Questions about Form Handling (Andrew M. Langmead)
Re: Attatching files with sendmail <webmaster@fccj.cc.fl.us>
Re: Avoiding $` uri@sysarch.com
Re: better way to do this? uri@sysarch.com
Calling Perl Scripts amerar@unsu.com
compile tk402.004 on Solaris 2.6 (Xiaojun Ping)
Re: Cookies (Jonathan Feinberg)
Re: glob problem (Nathan V. Patwardhan)
Re: glob problem (Andrew M. Langmead)
Re: Help: time a script in hundredth of second for Win3 (Jonathan Feinberg)
Re: Help: what is the simplest way to return the key of <dformosa@st.nepean.uws.edu.au>
Re: Help: what is the simplest way to return the key of (Andrew M. Langmead)
Re: How to get fractions of seconds (Jonathan Feinberg)
Re: if (-d $filename) in Win32 (Andrew M. Langmead)
Re: Off-topic (Sorry, but I need your help) <webmaster@fccj.cc.fl.us>
Re: Off-topic (Sorry, but I need your help) <webmaster@fccj.cc.fl.us>
Re: Perl and-or-vs TCL (Andrew M. Langmead)
Re: Perl in the movie "Sphere"? <webmaster@fccj.cc.fl.us>
Re: Perl4 -> Perl5 warning turned fatal message on open <webmaster@fccj.cc.fl.us>
Re: Perl4 -> Perl5 warning turned fatal message on open (Andrew M. Langmead)
Re: Perl4 -> Perl5 warning turned fatal message on open <rjk@coos.dartmouth.edu>
Re: Pure stupidity (hymie!)
REGEX : change string in HTML but not in HTML tag (Eric Loriaux)
Re: RegExp - To parse out dups in links pgm. (Jonathan Feinberg)
search and edit a single line of a Textfile <HaraldWolf@swol.de>
Re: What is the simpler way to find and erase duplicate <dformosa@st.nepean.uws.edu.au>
Re: Why is Tom Christiansen so rude? <jbc@west.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 22 Feb 1998 16:36:54 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: A Few Questions about Form Handling
Message-Id: <EosGtJ.DD3@world.std.com>
stephen farrell <sfarrell+usenet@farrell.org> writes:
>one other possibility would be to write a structure that encodes the
>desired order information... e.g.,
>%order = ( name => 0,
> whatever => 1,
> whateverelse => 2 );
>and then
>foreach ( sort { $order{$a} <=> $order{$b} } keys %FORM) { ...
If you need a "special" ordering, instead of sorting how about just
using a standard array holding the keys to the hash in the order you
want?
@order = qw(name whatever whateverelse);
foreach $key (@order) {
.... = $FORM{$key} ...
}
--
Andrew Langmead
------------------------------
Date: Sun, 22 Feb 1998 11:37:18 -0500
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: Attatching files with sendmail
Message-Id: <34F0543D.E9FB84E4@fccj.cc.fl.us>
[Hmmm, I already talked to you once today via e-mail???]
Anyways, for you 'lurks' here is a shortern version of my response:
DejaNews doesn't know me as 'Bill Jones Perl', it knows me
as 'Perl Sendmail Webmaster', or more to the point -
http://search.dejanews.com/dnquery.xp?QRY=perl+sendmail+webmaster&ST=QS&CT=&DBS=1&defaultOp=%26&svcclass=dncurrent&maxhits=20&showsort=score&format=terse&filter=&site=dn
HTH,
Bill
PS - My apologies to the rest for the 'URL'
:-)
Craig wrote:
> Bill,
>
> I did a search of dejanews and the only posting out of 53 that I found
> with the keywords "Bill Jones Perl" was this message. Could you repost the
> Perl code for emailing an attachment with Perl's sendmail program?
>
> Bill Jones wrote:
>
> > Yes, I have answered similar questions with complete source;
> > in Perl even...
> >
> > So a search of http://www.dejanews.com should give plenty
> > of answers :-)
> >
> > HTH,
> > Bill
> >
> > Robert Barker wrote:
> >
> > > Can u attatch files with sendmail???
> > >
> > > I want the user to select a file a html pulldown menu, fill in their
> > > email address and have the
> > > file sent back to them.
> > >
> > > Must be possible (and probably quite simple).
> > >
> > > Thanks
> > >
> > > --
> > > Robert Barker
> > > System's Development Manager
> > > Net7 Limited
> > > http://www.net7.co.uk/
> > >
> > > Tel: +44 (0)1924 444007
> > > Fax: +44 (0)1924 445507
> > >
> > > dataTRAK - Net7's Java Meta-Search Engine:
> > > http://datatrak.net7.co.uk
------------------------------
Date: 22 Feb 1998 17:23:51 -0500
From: uri@sysarch.com
Subject: Re: Avoiding $`
Message-Id: <x7ra4v2s94.fsf@sysarch.com>
Joe Gottman <joegottman@nospam.worldnet.att.net> writes:
> Tom Grydeland wrote:
>
> Another problem with the regular expression you use is that it consumes the
> entire string. This could be a major difference if you are matching using
> /regex/g. This is why in my original post I used
> /(a+)(?=(.*))/ . It is ugly, but it leaves $pos after the match at the same
> position as the original regex would have. I do agree that the way to get the
> prematch is with /(^.*?)/, so I think the best way to
> get all three is
> /^(.*?)(a+)(?=(.*\n?))/g
>
> The \n? should pick up the the trailing newline at the end of the string if there
> is one.
we should stop this thread and agree that ther is more than one way to
do it. the original problem never stated the true needs. does the string
have a trailing newline or was it chomped? is it in a /g context?
given a particular problem context we have shown several ways to not use
$[`&']
my assumptions were no newline and not /g. i would have answered
differently if they were required. the original poster seemed relatively
new and probably doesn't know about /s, /g and pos().
choose the weapon that is best for or most understood by you.
uri
--
Uri Guttman SYStems ARCHitecture and Software Engineering
uri@sysarch.com Have Perl, Will Hack
http://www.sysarch.com (781) 643-7504 x*2 FAX: (781) 643-2710
Try the Best Search Engine on the Net --------> http://www.northernlight.com
------------------------------
Date: 22 Feb 1998 17:59:59 -0500
From: uri@sysarch.com
Subject: Re: better way to do this?
Message-Id: <x7pvkf2qkw.fsf@sysarch.com>
mocat@NOSPAM.best.com (blacktape) writes:
> After learning a bit more about regexps, I've started work on a script
> that'll clean up my html files a bit. I was wondering if there is a
> better way to do this... I know it's crude, but it works. ;)
>
> Also, I was wondering if there is a way to read AND write to the same
> file... I've tried to do this in the past, but I've ended up having to
> open a seperate file for writing... it'd be so much easier if I could
> just do the whole shebang with one filehandle open.
>
> #!/usr/bin/perl
> open(HTMLFILE, "$ARGV[0]") or die "cant open $ARGV[0]: $!";
> @html = <HTMLFILE>;
> foreach $line (@html) {
> $line =~ /<img(.*?)>/i;
> $one = $1;
> if ($one !~ /alt\s?=/i) {
> $one =~ /.*?src\s?=\s?"(.*?)"/i;
> $one = $1;
> $line =~ s/src/alt="$one" src/i;
> print $line;
> } else {
> print $line;
> }
> }
first you waste code on opening the filename in @ARGV which is
accessible via <> (null filehandle). so you could start with:
> #!/usr/bin/perl
> while (defined( $line = <> ) ) {
then going one more step you can use the -n or -p options which will do
that loop for you. -n will not print the default line $_ and -p will
print it (these loops are derived from sed and awk).
this version lets you do the print of your line
> #!/usr/bin/perl -n
$line = <> ;
> $line =~ /<img(.*?)>/i;
> $one = $1;
> if ($one !~ /alt\s?=/i) {
> $one =~ /.*?src\s?=\s?"(.*?)"/i;
> $one = $1;
> $line =~ s/src/alt="$one" src/i;
> print $line;
> } else {
> print $line;
> }
the -p version prints for you so use $_ and not $line. also you always
print $line so remove it from the if statement
> #!/usr/bin/perl -p
> $_ =~ /<img(.*?)>/i;
> $one = $1;
> if ($one !~ /alt\s?=/i) {
> $one =~ /.*?src\s?=\s?"(.*?)"/i;
> $one = $1;
> $_ =~ s/src/alt="$one" src/i;
> }
you could remove the $_ from the lines since both // and s/// default to
$_.
finally, the -i option will work on the file and edit it in-place for you. -i
takes an optional value which is the suffix to use for the original
file. so you final program (without changing the $1 stuff and regex which could
also be improved) is:
> #!/usr/bin/perl -pi.old
> /<img(.*?)>/i;
> $one = $1;
> if ($one !~ /alt\s?=/i) {
> $one =~ /.*?src\s?=\s?"(.*?)"/i;
> $one = $1;
> s/src/alt="$one" src/i;
> }
here is the smallest version i can come up with, 3 lines (untested):
#!/usr/bin/perl -pi.old
# implied print loop over <> (@ARGV files), rewrite over the original
# file, save original file with .old suffix.
# skip lines without <img>
next unless /<img(.+?)>/i;
# skip lines with <img> and alt strings
next unless /<img.+?alt\s*=>/i
# sub src="string" with alt="string" src="string". this also removes
# the white space before and after the =
s/src\s*=\s*"(.*?)"/alt="$1" src="$1"/i ;
i'm sure this could be improved a little but it is very clear and simple
hope this helps,
uri
--
Uri Guttman SYStems ARCHitecture and Software Engineering
uri@sysarch.com Have Perl, Will Hack
http://www.sysarch.com (781) 643-7504 x*2 FAX: (781) 643-2710
Try the Best Search Engine on the Net --------> http://www.northernlight.com
------------------------------
Date: Sun, 22 Feb 1998 14:45:37 -0600
From: amerar@unsu.com
Subject: Calling Perl Scripts
Message-Id: <6cq2ve$ebr$1@nnrp2.dejanews.com>
Hello,
>From within an HTML document, how do I can a Perl script when no form or
button is involved?
For example, say I have a homepage:
<BODY>
... HTML CODE HERE ...
I want to call the perl script here
... MORE HTML CODE ...
</BODY>
How can I call the script unconditionally everytime the page is loaded?
Thank you for your help.
Arthur
amerar@unsu.com
http://www.unsu.com
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 19 Feb 1998 22:53:31 GMT
From: pingxj@karp.cs.albany.edu (Xiaojun Ping)
Subject: compile tk402.004 on Solaris 2.6
Message-Id: <6cid5b$ehd@maenad.csc.albany.edu>
I am trying to compile tk402.004 on solaris 2.6 by gcc 2.6.2,
but I got the following err message,
/usr/include/sys/select.h:45: warning: this is the location of
previous definition
In file include from /usr/include/sys/stream.h:26
from /usr/include/netinet/in.h:38
from /u/xiaojun/lib/perl5/sun4-solaris/5.00403/CORE/perl.h:361
from Bitmap.xs:8:
/usr/include/sys/model.h: #error "No DATAMODEL_NATIVE specified"
*** Error code 1
make Fatal error:command failed for target `Bitmap.o'
Cuttent working direcotry /u/xiaojun/src/Tk402.004/Bitmap
......
Does anyone know how to solve this problem ?
Thanks in advance
Xiaojun
------------------------------
Date: Sun, 22 Feb 1998 11:04:30 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Cookies
Message-Id: <MPG.f5a16995ab13a4b989729@news.concentric.net>
[courtesy cc of this posting sent to cited author via email]
dutchie@dutch.nl said...
: I'am searching how to make a cookie into a shopping programm, if the
: visiter leaves the site (after making a order but canceled it) and
: comes back in lets say 8 hours he/she becomes a cookie with the
: question :
: Would you like to continue your order yes or no.
:
: I'am willing to pat for it
I thought that a night of sleep would be enough to shake my buzz, but I guess
I was terribly, terribly wrong.
Dutchie, mon, you need to use CGI.pm, which comes with excellent
documentation. It provides the 'cookie' method, which makes trivial the
leaving and retrieving of cookies. If you have perl5.004, then you've already
got CGI.pm. If not, you should get perl5.004. Hope this helps.
--
#!/usr/bin/perl -w -- Just another Perl hacker,
(open 0),$_=<0>,s,.*- +,,,chop;for(split?@*?){($$_++or$}=$_,y,y \,\
y,<STDIN>,,$$=~s\^\"sub $_ {print'$}'};7"\ee),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 22 Feb 1998 14:25:17 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: glob problem
Message-Id: <6cpcgd$28k@fridge.shore.net>
Rob Duff (rduff@wimsey.com) wrote:
: I recently installed Slackware 3.4 without tcsh, and tried to install
: Tk403.004 and it failed. Can't find -lX11 anywhere. This turned
: out
Firstly, build your own Perl. Although I've heard that things (the
completeness of the Perl distribution that's bundled with Slackware)
have changed over time, are you sure that you want to trust that the
bundled versions of Perl in Slackware are complete?
Second, it doesn't sound like a problem with glob() one iota. Well,
at least this is what I can gather without any output from anything
like Makefile.PL or what have you. It sounds like it can find your X
libs for one. You could always send output of perl Makefile.PL to the
NG.
Third, I can't answer the stuff about tcsh and glob in Slackware Linux
... as this is a Perl NG. :-)
As a remedy, I'd suggest uninstalling your old version of Perl and
building the current, maintenance release of Perl -- perl5.004_04.
Then, build the Tk source against it. In terms of your Linux
environment, you should probably have a path to your X libraries in
LD_LIBRARY_PATH.
--
Nathan V. Patwardhan
------------------------------
Date: Sun, 22 Feb 1998 17:04:47 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: glob problem
Message-Id: <EosI3z.240@world.std.com>
rduff@wimsey.com (Rob Duff) writes:
> I installed tcsh manually, and got no improvement.
> I re-installed 3.4, this time with tcsh and the glob() started
>working,
You probably didn't install tcsh in the place that perl was looking
for it. Its probably looking for a file called "/bin/csh" or
"/usr/bin/csh". Maybe the initial installation makes a symlink to this
spot, but the "manual" installation does not.
If you are curious, you could probably say:
~>perl -V:full_csh
full_csh='/bin/csh';
See the perlrun or the Config.pm man page for details.
--
Andrew Langmead
------------------------------
Date: Sun, 22 Feb 1998 11:56:38 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Help: time a script in hundredth of second for Win32?
Message-Id: <MPG.f5a22ce3b005b098972a@news.concentric.net>
[courtesy cc of this posting sent to cited author via email]
tkho@technologist.com said...
: I am try to build a stop watch that count the time (in hundredth of
: second) for a script to finish. In Unix, I can use (times)[0], which
: return second up to two decimal place. How to run times on Win32?
Stop right there! Benchmark.pm comes with perl and works just fine on Win32.
Here's an example:
#!/usr/bin/perl -w
use Benchmark;
my $text = 'Now is the time for...';
sub foo {
for (my $i = 0; $i < 1000; $i++) {
my($beef, $jerky) = $text =~ /^([^.]*)(\.*)$/;
}
}
sub bar {
for (my $i = 0; $i < 1000; $i++) {
my($beef, $jerky) = $text =~ /^([^.]+)(\.+)$/;
}
}
timethese( 1000, {
'star' => \&foo,
'plus' => \&bar,
});
__END__
--
#!/usr/bin/perl -w -- Just another Perl hacker,
(open 0),$_=<0>,s,.*- +,,,chop;for(split?@*?){($$_++or$}=$_,y,y \,\
y,<STDIN>,,$$=~s\^\"sub $_ {print'$}'};7"\ee),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 22 Feb 1998 13:28:14 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Help: what is the simplest way to return the key of an associated array?
Message-Id: <888154089.757983@cabal>
In <34EFFDE5.8244ACC9@technologist.com> Tommy <tkho@technologist.com> writes:
>What is the simplest and fastest way to return the key of an associated
>array?
>my %Array= ("A" => 65, "B"=> 66, "C" => 67, "D" => 68);
>@ANS= &key(VALUE => 67, ARRAY= \%Array);
sub key {
my %arg=@_;
my $value=$arg{VALUE};
my %array=reverse %{$arg{ARRAY}}; #Should realy be called hash
return $array{$value};
}
when reverse is called on a hash it inversts it and gets the behavour you
want.
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep.
Support NoCeM http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Sun, 22 Feb 1998 16:50:08 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Help: what is the simplest way to return the key of an associated array?
Message-Id: <EosHFs.Ist@world.std.com>
? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au> writes:
>In <34EFFDE5.8244ACC9@technologist.com> Tommy <tkho@technologist.com> writes:
>>What is the simplest and fastest way to return the key of an associated
>>array?
[meaning "how do I find the corresponding key in a hash whose value
matches the given value]
>when reverse is called on a hash it inversts it and gets the behavour you
>want.
As the FAQ points out <URL:http://www.perl.com/CPAN/doc/manual/html/
perlfaq4/How_do_I_lok_up_a_hash_element_.html> this only works if the
values are unique. It also shows a less memory costly method of
performing the same task.\
And obviously, if you are going to be doing ` lookups both ways
frequently, you are better off either making the inverse hash as you
make the original one, or at least keeping the inverse hash around
once you've made it.
--
Andrew Langmead
------------------------------
Date: Sun, 22 Feb 1998 10:49:04 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: How to get fractions of seconds
Message-Id: <MPG.f5a12fefab8905d989728@news.concentric.net>
[courtesy cc of this posting sent to cited author via email]
hanklem@ibm.net said...
: In perl, how do you determine the time down to fractions of seconds?
That would be perlfaq8, "How can I measure time under a second?"
Please note that your sig might be considered about 400% too big for most
people's comfort.
--
#!/usr/bin/perl -w -- Just another Perl hacker,
(open 0),$_=<0>,s,.*- +,,,chop;for(split?@*?){($$_++or$}=$_,y,y \,\
y,<STDIN>,,$$=~s\^\"sub $_ {print'$}'};7"\ee),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Sun, 22 Feb 1998 16:32:39 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: if (-d $filename) in Win32
Message-Id: <EosGMF.AIv@world.std.com>
jdf@pobox.com (Jonathan Feinberg) writes:
>perl.user@sndk.se said...
>: Why isn't the following ok in Win32? Is -d only working in unix perl?
>: I want to scan the whole of d:\ for perl-files (extension "pl").
>: @dirs =
>: (
>: 'd:\\'
>: );
>Oof. Get rid of those backslashes; Perl treats / as the directory separator
>on all platforms.
> @dirs = ( 'd:/' );
Untrue. Perl does no special processing of path separators. (Except
maybe the VMS port, I haven't looked at that.)
Perl just passes the filename onto the C library functions that it is
built upon. Those functions are usually wrappers operating system
calls. And on platforms that treat a forward slash as a path separator
(Which includes MS-DOS and its descendents. The operating system
kernel (cough cough) treats both forward and backslashes identically.)
the forward slash is the obvious choice to use as a path separator.
And since the Macintosh uses neither forward nor back slash as the
path separator, if it didn't work that way, perl would be unable to
open a file with a valid and commonly used character.
--
Andrew Langmead
------------------------------
Date: Sun, 22 Feb 1998 11:19:12 -0500
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: Off-topic (Sorry, but I need your help)
Message-Id: <34F05000.5E4BA1E4@fccj.cc.fl.us>
Well, why haven't you shared your hash, er, stash?
:-)
Jonathan Feinberg wrote:
> allie@icct.net said...
> : I know this off-topic and I apologize, but I've been
> : really impressed with the knowledge and helpfulness of
> : the people in this NG and I thought you might be able
> : to help.
>
> I guess I shouldn't smoke the really strong shit before catching up on
> c.l.p.m. I thought it would help.
>
<Snip other hilarious stuff...>
------------------------------
Date: Sun, 22 Feb 1998 11:25:06 -0500
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: Off-topic (Sorry, but I need your help)
Message-Id: <34F05161.DE87BE44@fccj.cc.fl.us>
Allie wrote:
> I know this off-topic and I apologize,
Way off topic, so the short answer is -
Unix kicks asss,
Unix is the standard,
MS does not run on Unix,
Get with the program...
I hope this has been helpful,
Bill
PS - I just spent about a week setting up
a Lotus Notes/Domino/Go Web/Note clients...
What I found was, it does not do a thing that
I could not ALREADY do using Unix - and
without all the blasted overhead, but I suppose
that is why Bill, et al, have billions, huh?
------------------------------
Date: Sun, 22 Feb 1998 16:19:43 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Perl and-or-vs TCL
Message-Id: <EosG0v.3L9@world.std.com>
Dale Phillips <dphi@ix.netcom.com> writes:
>I know that this is a loaded quesiton.
>Does anyone know where I can fairly and equally compare.
>I use perl now but know nothing of tcl.
I went <URL:http://www.altavista.digital.com/> and typed in "perl tcl
comparison" and some other search phrases. I found a lot of web pages
that discuss the two languages.
Where have you researched your question so far?
<URL:http://wave.gsfc.nasa.gov/perlvstcl2.html>
<URL:http://sunset.usc.edu/~horowitz/Homework/lauraX/critique.html>
<URL:http://icemcfd.com/tcl/comparison.html>
--
Andrew Langmead
------------------------------
Date: Sun, 22 Feb 1998 11:42:17 -0500
From: Bill Jones <webmaster@fccj.cc.fl.us>
Subject: Re: Perl in the movie "Sphere"?
Message-Id: <34F05569.E0263F1D@fccj.cc.fl.us>
I guess there is still hope I can be a movie star? :-)
Bill
Sean McAfee wrote:
> I just got back from seeing the new movie "Sphere", and I think I saw part...
<Snip, other non-perl stuff snipped>
------------------------------
Date: Sun, 22 Feb 1998 11:49:46 -0500
From: Bill Jones <webmaster@fccj.cc.fl.us>
To: enaiman <enaiman@ndsisrael.com>
Subject: Re: Perl4 -> Perl5 warning turned fatal message on open() call
Message-Id: <34F05729.55CB5A60@fccj.cc.fl.us>
[Curtsey reply via e-mail as well...]
Short answer is, don't do that. Stick with perl 5; and use
#!/path/to/perl -w
use strict;
my $someFile = "/etc/passwd";
open (fhInput, "$someFile") or die("Oops $!\n");
while (<>) {
chomp;
print "I found this line:\n$_\nShould I delete it? Hmmm, nah, I
won't...\n";
}
close(fhInput);
But then again, you knew that from reading all the available docs
on this subject, huh?
HTH,
Bill
enaiman wrote:
> Dear All,
>
> Due to some server problems, please reply to my address as well as the
> newsgroup (if appropriate).
>
> Here's my question:
>
> #!/usr/local/bin/perl -w
> local($fh);
> if(open($fh, "< no_such_file") == 0)
> {
> die("Could not open \"no_such_file"\" for reading: ", $!);
> }
> close($fh);
> exit(0);
>
> In Perl4, the open line would give a warning and in Perl5 it is fatal.
>
> What gives? What is the official way to work with indirect filehandles?
>
> I know that there are "use IO" modules that get around this problem by
> creating more logical interfaces to open and close.
> (I also know about using my instead of local, I just wanted a script that
> ran in both 4 & 5.)
>
> I'm working on upgrading a system written in Perl 4.036 to Perl5, and I
> don't want to have to re-write everything. Where can I find a complete
> list of CHANGES between Perl 4 and 5? I have read some of them and haven't
> found a reference to the above problem.
>
> Any help is appreciated.
>
> Thanx,
>
> Ephrayim "EJ" Naiman
> NDS Technologies Israel Limited
> enaiman@ndsisrael.com
------------------------------
Date: Sun, 22 Feb 1998 17:08:27 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Perl4 -> Perl5 warning turned fatal message on open() call
Message-Id: <EosIA4.4Es@world.std.com>
"enaiman" <enaiman@ndsisrael.com> writes:
>#!/usr/local/bin/perl -w
>local($fh);
>if(open($fh, "< no_such_file") == 0)
[stuff deleted]
>In Perl4, the open line would give a warning and in Perl5 it is fatal.
Even if the file handle is indirect, it still has to indirectly point
to something.
Perl 4 allowed a zero length string to be the name of a filehandle,
perl 5 does not.
If you initialize $fh to something (except '' I guess), it will work
in both versions.
--
Andrew Langmead
------------------------------
Date: Sun, 22 Feb 1998 17:27:41 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: enaiman <enaiman@ndsisrael.com>
Subject: Re: Perl4 -> Perl5 warning turned fatal message on open() call
Message-Id: <34F0A660.1647EE92@coos.dartmouth.edu>
[posted and mailed]
enaiman wrote:
>
> #!/usr/local/bin/perl -w
> local($fh);
> if(open($fh, "< no_such_file") == 0)
> {
> die("Could not open \"no_such_file"\" for reading: ", $!);
> }
> close($fh);
> exit(0);
>
> In Perl4, the open line would give a warning and in Perl5 it is fatal.
>
> What gives? What is the official way to work with indirect filehandles?
Apparently, Perl4 allows you to use the undefined value as a filehandle, and
Perl5 doesn't. I don't know why you'd want to use an undefined value as a
filehandle anyway. What are you really trying to do?
This seems to work:
local($fh) = "whatever";
if(open($fh, "< no_such_file") == 0)
{
die("Could not open \"no_such_file"\" for reading: ", $!);
}
print <$fh>;
close($fh);
exit(0);
A better way to do it is this:
use FileHandle;
local($fh) = new FileHandle;
...
(BTW, your code would give a syntax error in either version; you have an extra
". What does your code really look like?)
--
_ / ' _ / rjk@coos.dartmouth.edu
( /)//)//)(//)/( chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
------------------------------
Date: 22 Feb 1998 15:48:37 GMT
From: hymie@lactose.smart.net (hymie!)
Subject: Re: Pure stupidity
Message-Id: <6cphcl$oms$1@news.smart.net>
In our last episode, the evil Dr. Lacto had captured our hero,
Grimoire <grimoire@oaktree.net>, who said:
>THE CODE:
>--- ----
>#!/usr/bin/perl
>
>$pw = '/etc/passwd';
>print "Who are you looking for? ";
>chomp($a = <>);
>open(PW, $pw) || die "cannot open $pw: $!";
>while(<PW>){
> if($pw =~ /\$a/i){
Have you determined what this line will do? How does it expand?
if (/etc/passwd matches-case-insensitive $a)
I don't see any similarity between the string /etc/passwd and the
string $a . The if statement will be false every time.
> print $_;
> }
>}
..hymie!
http://www.smart.net/~hymowitz * agis customers: e-mail and web service refused
hymie@lactose.smart.net ********** pgp public key: e-mail pgp@lactose.smart.net
===== Unsolicited commercial e-mail spam will be forwarded to postmasters =====
------------------------------
Date: Sun, 22 Feb 1998 13:56:23 GMT
From: Eric.Loriaux@ping.be (Eric Loriaux)
Subject: REGEX : change string in HTML but not in HTML tag
Message-Id: <34f02d64.7088151@news.ping.be>
Hi there !
Is there someone around who could explain the best way I could change
strings by something else IF the matching string isn't part of an html
tag <...> ?
For instance, how can I change "Welcome" into "Welcome (main)" in this
context :
before :
<A HREF="http://www.loriaux.com/s390/Welcome.html">Welcome page</A>
<BR>This is the Welcome page.
after :
<A HREF="http://www.loriaux.com/s390/Welcome.html">Welcome (main)
page</A> <BR>This is the Welcome (main) page.
So, >...string...< is ok but <... string...> is not.
The real purpose is to change html to include <font color...> tags
(which, of course, should be avoided if the found string is part of a
URL) in the output of a search script (the cgi is ok, I just want
users to see at a glance where the matching strings were found).
Best regards,
Eric Loriaux's System/390 home page,
http://www.ping.be/~ping1475 (Europe)
http://www.instantweb.com/l/loriaux/s390 (USA)
------------------------------
Date: Sun, 22 Feb 1998 10:46:28 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: RegExp - To parse out dups in links pgm.
Message-Id: <MPG.f5a125d3db74223989727@news.concentric.net>
[courtesy cc of this posting sent to cited author via email]
johnr@pacificnet.net said...
: <li><a href="http://www.svr.com/dir/default.htm" >Spamm1
: I need to takesvr.com/dir.... up to the last / and save it.
: Do the same for the input url compare etc.. The regexp for this is
: a little tough for me. Please Help :-)
Here's a crude attempt that will work with all of the data you showed, thought
I'm sure you can refine it to capture other URLs as exceptions crop up.
#!/usr/bin/perl -w
$line = '<li><a href="http://www.svr.com/dir/default.htm" >Spamm1';
$line =~ m{
href=" # bounded by this literal on the left
((?:[^"/]*/)*) # a bunch of directory segments, captured to $1
([^"]*) # the document name, captured to $2
" # bounded rightside by the closing quote
}xi;
print "$1\n$2\n";
If any of the symbols in that regex throw you, then you should make a cup of
coffee and settle down with the perlre document. Hope this helps.
--
#!/usr/bin/perl -w -- Just another Perl hacker,
(open 0),$_=<0>,s,.*- +,,,chop;for(split?@*?){($$_++or$}=$_,y,y \,\
y,<STDIN>,,$$=~s\^\"sub $_ {print'$}'};7"\ee),y,} \,},>STDOUT,,&$_}
# Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Sun, 22 Feb 1998 16:19:45 +0100
From: Harald Wolf <HaraldWolf@swol.de>
Subject: search and edit a single line of a Textfile
Message-Id: <34F04211.ED9C38E4@swol.de>
Hi,
how can i write a program which gives me one line from a ascii-file
which always starts with "servertasks=" for editing and save it in this
ascii-file.
please help a perl-beginner !
------------------------------
Date: 22 Feb 1998 13:37:42 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: What is the simpler way to find and erase duplicated array?
Message-Id: <888154659.444687@cabal>
In <34EFF86E.8B251088@technologist.com> Tommy <tkho@technologist.com> writes:
>What is the simpler way to find and erase duplicated array?
>For example:
#unique
@unique = grep {$temp{$_}++<=1} @array;
@duplicate = grep {$temp{$_}++>1} @array;
------------------------------
Date: Sun, 22 Feb 1998 09:14:46 -0800
From: John Callender <jbc@west.net>
Subject: Re: Why is Tom Christiansen so rude?
Message-Id: <34F05D06.37C855ED@west.net>
It's just his personality. He's basically a rude person. It's probably
rooted in his upbringing, or his genetic makeup, or something; I get the
sense there's some sort of underlying insecurity involved. But that's
not really important. For better or worse, it's just the way he is.
I was really looking forward to meeting him at the O'Reilly Perl
Conference. I signed up for his pre-conference CGI workshop, even though
I (like most of the audience, it turns out) already knew most of what he
was going to talk about.
At the break I waited around the podium with a number of other
questioners, and when things had thinned out I approached him with my
blue camel and asked him if he'd autograph it.
"The book signing is Thursday," he snapped, turning immediately to the
next questioner.
It was kind of cool, being eerily reminiscent of the rude treatment he
gives newbies in c.l.p.m. (I hadn't bothered reading the handout packet
that morning. That packet did, in fact, say that the book signing would
be on Thursday. Duh.)
If that was cool, though, the signing was awesome: I saw the entire
sweep of c.l.p.m social interaction, compressed into one little corner
of a meeting room:
Larry -- Getting caught up in his own little world, playing creatively
with a TMTOWTDI stamp to give each of the several hundred signees their
own uniquely personal autograph.
Randal -- Signing each book carefully and precisely, doing a
responsible, workmanlike job, while chatting matter-of-factly about his
legal troubles.
Tom -- Doing a slow burn at the horrible inefficiency of having to sit
there signing his name over and over again, his hand visibly cramping,
his expression becoming increasingly dour as my part of the line snaked
its way across the floor to the signing table, and finally, when I got
to him, dashing off an angry, illegible scrawl, then thrusting the book
aside and grabbing the next one, head down, not even making eye contact.
That was almost worth the price of the conference right there.
Oh, I almost forgot:
Tom Phoenix -- Circulating among the people waiting in line, helping
out, telling jokes, and generally being as pleasant and patient as Tom
C. is not.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 1952
**************************************