[13642] in Perl-Users-Digest
Perl-Users Digest, Issue: 1052 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 12 16:05:27 1999
Date: Tue, 12 Oct 1999 13:05:08 -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: <939758708-v9-i1052@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 12 Oct 1999 Volume: 9 Number: 1052
Today's topics:
Re: A perl dereferencing problem manojska@my-deja.com
Access to ARGV from XS? yacob99@my-deja.com
CGI File Upload on WinNT <@mdo.net>
Re: Dos commands in Perl??????????? <aqumsieh@matrox.com>
figured it out <david@kasey.umkc.edu>
how do i open a new window from a cgi script eleedumas@my-deja.com
How do you parse a textarea as one line? emlyn@cimedia.com
Re: How to get last dir from path??????????? <msalter@bestweb.net>
Re: How to get last dir from path??????????? <dove@synopsys.com>
Making a hash of subroutines schablone@my-deja.com
Re: Making a hash of subroutines <dove@synopsys.com>
Re: Making a hash of subroutines <dave@dave.org.uk>
Re: Making a hash of subroutines (Andrew Johnson)
Re: non-ascii <rootbeer@redcat.com>
Out of Office AutoReply: Deja.Com Daily Digest: comp.la <james@xch.net>
Re: Perl Interview Question: (Larry Rosler)
Re: Perl lite (Abigail)
Re: Sending mail with Perl? <dove@synopsys.com>
Re: Slideshow script <rootbeer@redcat.com>
Typeglob bug? <shubro@topservice.com>
Re: Typeglob bug? <uri@sysarch.com>
Re: use strict <rootbeer@redcat.com>
Re: Using Perl to add line nums? <aqumsieh@matrox.com>
Re: using the 'foreach' loop to split a string <rootbeer@redcat.com>
Where to find Perl scripts? <RyanM019@rem0veThis.home.com>
Re: Where to find Perl scripts? <dove@synopsys.com>
working perl -pie workaround <david@kasey.umkc.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 12 Oct 1999 19:02:59 GMT
From: manojska@my-deja.com
Subject: Re: A perl dereferencing problem
Message-Id: <7u00kp$7iv$1@nnrp1.deja.com>
In article <37fe9872_5@news5.newsfeeds.com>,
"David Christensen" <dchristensen@california.com> wrote:
> manojska:
>
> Please post more code and a sample run.
>
> --
> David Christensen
> dchristensen@california.com
Thanks David, for replying.
It was a bug in my script. Incorrect initialization of an array.
Thanks again
manojska
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 12 Oct 1999 19:41:24 GMT
From: yacob99@my-deja.com
Subject: Access to ARGV from XS?
Message-Id: <7u02t0$9he$1@nnrp1.deja.com>
Can't find any info on this...
...from within XS code do we have access to @ARGV somehow?
thanks in advance!
/Daniel
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 12 Oct 1999 15:48:55 -0400
From: "CS" <@mdo.net>
Subject: CGI File Upload on WinNT
Message-Id: <2eMM3.10645$UG5.624484@typ11.nn.bcandid.com>
You can upload a file to a remote Unix/Linux server from a browser if you
first chmod 777 the target directory.
But if you want to do a similar thing on a remote NT Server, what should you
do? What are your options? (besides switching to a non NT server :-)
I know this isn't exactly a perl question, but I'm making a perl script that
would do something like this. I already have one that works fine for a
linux/unix server.
Advice much appreciated. Thanx in advance.
Regards, Chris S.
------------------------------
Date: Tue, 12 Oct 1999 13:36:12 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Dos commands in Perl???????????
Message-Id: <x3yiu4c7a7n.fsf@tigre.matrox.com>
krun@my-deja.com writes:
> How would one use dos commands such as dir and cd in perl? Also if
By a DOS command, do you mean a shell command? Or do you want the
equivalent of the DOS 'cd' and 'dir' commands in Perl?
> there is a way what kind of information is returned when a dir is run?
Yes.
> Does it return a true(1) or false(0) depending on wether it found
> path? If there isn't command lines for Dos, how would one go about
Hmmm... 'dir' returns a list of file names in the current directory. I
don't get what the true or false values are supposed to mean. What do
you mean "whether it found a path" ?
> searching a directory for a specific path? Thank you for your help and
> response.
If you want to run a shell command from a Perl program, then you
should look at the following commands:
system()
qx()
open()
If you want to read the contents of a directory in a Perl program,
then you should look at the following commands:
opendir()
readdir()
closedir()
The following command might also prove useful:
grep()
The following perldocs will be useful:
perlop
perlre
perlfunc
In any case, you should be reading more of the perl
documentation. This should infact be your first line of defense
against your Perl programming obstacles.
HTH,
--Ala
------------------------------
Date: Tue, 12 Oct 1999 18:41:07 +0000
From: "David L. Nicol" <david@kasey.umkc.edu>
Subject: figured it out
Message-Id: <380380C3.8E493A7D@kasey.umkc.edu>
it's because -i takes an argument.
perl -pi -e s/\\bNichol\\b/Nicol/g *.txt
works.
_______________________________________________________
David Nicol 816.235.1187 nicold@umkc.edu
echo s/\\bNichol\\b/Nicol/g>p; perl -pi p *
------------------------------
Date: Tue, 12 Oct 1999 19:47:17 GMT
From: eleedumas@my-deja.com
Subject: how do i open a new window from a cgi script
Message-Id: <7u0380$9n2$1@nnrp1.deja.com>
I have a CGI perl script that gets some data via a
form from the user, queries a database, and
generates some results, which I pass back to the
user via the same page with the initial form. I
would like to return the form query in the
original page, but put the results into a new
window. How do I do that? I have looked in the
O'reilly books as well as several other perl
resourses and can't find how to do this. Thank
you in advance for your help
elee
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 12 Oct 1999 19:21:52 GMT
From: emlyn@cimedia.com
Subject: How do you parse a textarea as one line?
Message-Id: <7u01o0$8i4$1@nnrp1.deja.com>
I've read some questions about replacing \n with <br> tags for
paragraph breaks in a form textarea, but what if you simply want the
textarea to be written to a field as one long line (with or without
<br>s)?
Does there need to be a special "wrap" tag included in the html
(virtual,physical,off) before it's sent to the cgi? I've tried all
kinds of approaches (using MacPerl), but for every linebreak, it
inserts an unrecognizable square character - very strange.
Hope there are some ideas out there...
E.
emlyn1@home.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 12 Oct 1999 19:45:25 GMT
From: Mike Salter <msalter@bestweb.net>
Subject: Re: How to get last dir from path???????????
Message-Id: <Pine.BSF.4.05.9910121550200.7811-100000@monet.bestweb.net>
Try something like:
$_ = '.\alpha\prod\debug\exe\extsw\MedCom_src';
if(/.+\\/) {
print $';
}
On Tue, 12 Oct 1999 krun@my-deja.com wrote:
>Date: Tue, 12 Oct 1999 18:15:14 GMT
>From: krun@my-deja.com
>Newsgroups: comp.lang.perl.misc
>Subject: How to get last dir from path???????????
>
>How can I parse out the last dir. from a path? For example I have the
>following in an array:
>
>.\alpha\prod\debug\exe\extsw\MedCom_src
>.\alpha\prod\debug\exe\extsw\MedCom_src\AT
>.\alpha\prod\debug\exe\extsw\MedCom_src\AT\genericmain
>.\alpha\prod\debug\exe\extsw\MedCom_src\AT\genericmain\src
>.\alpha\prod\debug\exe\extsw\MedCom_src\AT\gmaincompmfc
>
>How would I get:
>
>MedCom_src
>AT
>genericmain
>src
>gmaincompmfc
>
>into a different array? Thank you.
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
>
>
------------------------------
Date: Tue, 12 Oct 1999 12:46:52 -0700
From: David Amann <dove@synopsys.com>
Subject: Re: How to get last dir from path???????????
Message-Id: <3803902C.3812F478@synopsys.com>
Hi,
krun@my-deja.com wrote:
> How can I parse out the last dir. from a path? For example I have the
> following in an array:
>
> .\alpha\prod\debug\exe\extsw\MedCom_src
> .\alpha\prod\debug\exe\extsw\MedCom_src\AT
> .\alpha\prod\debug\exe\extsw\MedCom_src\AT\genericmain
> .\alpha\prod\debug\exe\extsw\MedCom_src\AT\genericmain\src
> .\alpha\prod\debug\exe\extsw\MedCom_src\AT\gmaincompmfc
>
> How would I get:
>
> MedCom_src
> AT
> genericmain
> src
> gmaincompmfc
>
> into a different array?
The quick answer is to use the 'basename' routine from the File::Basename
module. The File::Basename module has a few routines to help out with a
lot of this sort of stuff. For example:
use File::Basename;
my $path = "/a/real/long/path/to/this/file.txt";
$base = basename($path); # This will get just the filename in
# a long path. In this case "file.txt"
# would be returned.
$dir = dir($path) # This will get the directory. In
# this case: /a/real/long/path/to/this
($base, $dir, $ext) = fileparse($path);
#After this, $base = file, $dir = /a/real/long/path/to/this, and
#$ext = .txt
You'll want to be careful with the extension part of this. For more
info, check out the Perl Cookbook, by Tom Christiansen and Nathan
Torkington.
Here's a script to solve your particular problem:
#!/usr/local/bin/perl-5.004 -w
# Always use -w to catch errors.
#
# Author: Dav Amann (dove@synopsys.com)
# Version: 1.0
#
use strict; # Always use strict.
use File::Basename;
my @paths =
("alpha/prod/debug/exe/extsw/Medcom_src",
"alpha/prod/debug/exe/extsw/Medcom_src/AT",
"alpha/prod/debug/exe/extsw/Medcom_src/AT/genericmain",
"alpha/prod/debug/exe/extsw/Medcom_src/AT/genericmain/src",
"alpha/prod/debug/exe/extsw/Medcom_src/AT/gmaincompmfc"
);
my @files =();
foreach my $path (@paths) {
push @files, basename($path);
}
foreach my $file (@files) {
print "$file\n";
}
------------------------------
Date: Tue, 12 Oct 1999 19:20:25 GMT
From: schablone@my-deja.com
Subject: Making a hash of subroutines
Message-Id: <7u01l8$8hl$1@nnrp1.deja.com>
Hi folks, it's Schablonski here again.
My plan for world domination is proceeding pretty well and I'm working
on a databasey-type application to keep track of my enemies and their
favourite types of sandwich.
For various perverse and twisted reasons I wish to pass some values
in a hash to a subroutine. Unfortunately men in black suits are beaming
radiowaves at my brain and I am unable to think properly, so I can't get
my code (below) to work.
I know hashes are flattened in subroutine calls, so I want to pass a
reference to the hash. Only it doesn't seem to work. Am I barking up the
wrong tree?
If anyone can help me on this one, the post of Lord High Keeper of Tall
Lattes and Pineapple Cubes is theirs for the asking (once I've actually
got the Umbrella of World Power in my hands, that is).
Yours rubbing his hands in glee and making strange noises
Schablonski
Here's the code:
#!/usr/bin/perl -w
#use strict;
my %test;
my @data;
@data = ('244', 'Slightly Evil Bob', 'Chicken & Cucumber');
%test = (
id => $data[0],
name => $data[1],
sandwich => $data[2]
);
DoSomething (\%test, "Favourite Sandwich Data for: ");
exit(0);
sub DoSomething {
my %Newhash = shift;
my $message = shift;
print $message;
print $Newhash{'name'}."\n";
print $Newhash{'sandwich'};
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 12 Oct 1999 12:58:56 -0700
From: David Amann <dove@synopsys.com>
Subject: Re: Making a hash of subroutines
Message-Id: <38039300.AE650ECE@synopsys.com>
Hi Schlab,
schablone@my-deja.com wrote:
> I know hashes are flattened in subroutine calls, so I want to pass a
> reference to the hash. Only it doesn't seem to work. Am I barking up the
> wrong tree?
Looks like you need a big hopping dose of 'perldoc perlref'
But here's a quick fix to your code.
#!/usr/local/bin/perl-5.004 -w
# Always use -w to catch errors.
#
# Author: Dav Amann (dove@synopsys.com)
# Version: 1.0
#
use strict; # Always use strict.
my @data = ("244",
"Slightly Evil Bob",
"Chicken & Cucumber");
my %test = ("id" => $data[0],
"name" => $data[1],
"sandwich" => $data[2],
);
my $message = "Favorite Sandwich Data for:";
DoSomething(\%test, $message); #Notice the \ here to pass the
#reference to the hash rather
#than a copy of the hash.
sub DoSomething {
my $r_hash = shift; #$r_hash now holds the address of
# %test
my $message = shift;
# Check out the following to see how to get stuff out of
# The hash reference.
print "$message\n";
print "ID: " . $r_hash->{"id"} . "\n";
print "Name: " . $r_hash->{"name"} . "\n";
print "Sandwich: " . $r_hash->{"sandwich"} . "\n";
}
Take care,
-=dav
------------------------------
Date: Tue, 12 Oct 1999 21:05:12 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: Making a hash of subroutines
Message-Id: <f5MDOIhSuakfD+409kCqDSSBtBqx@4ax.com>
On Tue, 12 Oct 1999 19:20:25 GMT, schablone@my-deja.com wrote:
[snip]
>I know hashes are flattened in subroutine calls, so I want to pass a
>reference to the hash. Only it doesn't seem to work. Am I barking up the
>wrong tree?
[snip]
>Here's the code:
>
>
>#!/usr/bin/perl -w
>#use strict;
>
>my %test;
>my @data;
>
>@data = ('244', 'Slightly Evil Bob', 'Chicken & Cucumber');
>
>%test = (
> id => $data[0],
> name => $data[1],
> sandwich => $data[2]
> );
>
>DoSomething (\%test, "Favourite Sandwich Data for: ");
>
>exit(0);
>
>
>sub DoSomething {
> my %Newhash = shift;
> my $message = shift;
>
> print $message;
> print $Newhash{'name'}."\n";
> print $Newhash{'sandwich'};
>}
You're passing hash reference into your subroutine, but once inside
you treat it like a hash _not_ a reference. You need to rewrite your
DoSomething routine like this:
sub DoSomething {
my $Newhashref = shift;
my $message = shift;
print $message;
print $Newhashref->{name}, "\n";
print $Newhashref->{sandwich}'
}
You also need to take a closer look at perlref and perlsub where these
things are explained in some detail.
hth,
Dave...
--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>
------------------------------
Date: Tue, 12 Oct 1999 20:03:55 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Making a hash of subroutines
Message-Id: <LuMM3.22232$Vg4.942508@news1.rdc2.on.home.com>
In article <7u01l8$8hl$1@nnrp1.deja.com>,
schablone@my-deja.com <schablone@my-deja.com> wrote:
[snip]
! I know hashes are flattened in subroutine calls, so I want to pass a
! reference to the hash. Only it doesn't seem to work. Am I barking up
! the wrong tree?
nope, passing a reference to the hash is the right tree, you must
be barking wrong:
[snip]
! DoSomething (\%test, "Favourite Sandwich Data for: ");
okay, you've passed a reference to %test ... remember, a reference
is a scalar value...
[snip]
! sub DoSomething {
! my %Newhash = shift;
your first argument in @_ is a scalar (you passed a hash ref remember)
but you are assigning it to a hash --- you should assign it to a
scalar variable:
my $newhashref = shift;
# or dereference and copy it
#
# my %Newhash = %{shift()};
! my $message = shift;
!
! print $message;
! print $Newhash{'name'}."\n";
! print $Newhash{'sandwich'};
and now you'll have to change these to dereference the hashref
appropriately: (assuming you didn't make a copy instead)
print $newhashref->{name},"\n";
print $newhashref->{sandwich};
! }
hope it helps,
andrew
--
Andrew L. Johnson
http://www.manning.com/Johnson/
In theory, there's no difference between
theory and practice, but in practice there is!
------------------------------
Date: Tue, 12 Oct 1999 12:38:49 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: non-ascii
Message-Id: <Pine.GSO.4.10.9910121238120.19155-100000@user2.teleport.com>
On Tue, 12 Oct 1999, Sebastian Lorr wrote:
> hallo!, i am trying to convert information extracted as a text file
> from the directory server into a PDF file. within the directory
> server applications i have no problems with non-ascii characters (such
> as umlauts) because everyting is encoded in UTF-8. my problem now is
> to find an application which can correctly convert to PDF the umlauts
> in the original text file. the txt to PDF converter which i am
> currently using (written in Perl) unfortunately "skips" all umlaut
> characters . does anyone know of any PDF converter tool which handles
> non-asci characters?
If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 12 Oct 1999 19:49:46 +0100
From: james huckle <james@xch.net>
To: "comp.lang.perl.misc@list.dejanews.com" <comp.lang.perl.misc@list.deja.com>
Subject: Out of Office AutoReply: Deja.Com Daily Digest: comp.lang.perl.mi sc 2/4
Message-Id: <417B2724FB63D311ABD202608C7D60F103F2CC@msx.xch.net>
I have left OSP, please send support messages to
support@xch.net
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 12 Oct 1999 12:00:22 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Interview Question:
Message-Id: <MPG.126d2520715e2b7998a081@nntp.hpl.hp.com>
In article <7tvu0d$5g6$1@nnrp1.deja.com> on Tue, 12 Oct 1999 18:18:07
GMT, The Glauber <theglauber@my-deja.com> says...
> In article <MPG.126c274d80e79f2798a07a@nntp.hpl.hp.com>,
> lr@hpl.hp.com (Larry Rosler) wrote:
...
> > From perlsyn:
> >
> > The foreach loop iterates over a normal list value and sets the
> variable
> > VAR to be each element of the list in turn. If the variable is
> preceded
> > with the keyword my, then it is lexically scoped, and is therefore
> > visible only within the loop. Otherwise, the variable is implicitly
> > local to the loop and regains its former value upon exiting the loop.
>
> Except that there wasn't any "my" in that code!
That's what the 'Otherwise,' at the beginning of the sentence refers to
-- no 'my'. So the effect of the foreach loop on its variable is
invisible whether or not the variable has a 'my' declaration.
> According to "Learning Perl" (Llama) chapter 4, the loop variable in
> foreach is always local to the foreach, and it always reverts to its
> previous value (or undef) after the loop. The same information in
> different words in Camel, 2.6.4.3
>
> I didn't know this, and i'm glad i know it now!
Then asking the question was worthwhile, after all!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Oct 1999 14:49:29 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl lite
Message-Id: <slrn80745l.gep.abigail@alexandra.delanet.com>
Dan Sugalski (dan@tuatha.sidhe.org) wrote on MMCCXXXIII September
MCMXCIII in <URL:news:wCMM3.481$IZ5.14254@news.rdc1.ct.home.com>:
!! The Glauber <theglauber@my-deja.com> wrote:
!!
!! > Perl's load time is not significantly impacted by having a shared lib.
!! > Sometimes, if you run perl multiple times in quick sucession, the first
!! > one will take about 1 second to load, the others are instant. I guess
!! > it must remain loaded for a couple minutes after perl exits, in case
!! > it's needed again. Or whatever.
Well, that's why you have a cache... ;-)
!! Hmmm. Configure definitely warns about slowdowns. On the other hand, I
!! know AIX resolves its symbols at link time instead of runtime (like
!! VMS does) so it may be that you pay the price when perl's built rather
!! than when perl's invoked.
Well, just saying "it's slower on this OS, and there's no penalty on
this OS" is only half of the story.
The other half is at least as important, and is "how are you using perl?".
At my previous job, we noticed a definitive improvement when going from
a static to a dynamic perl, when the main use of Perl was for a badly
written Perl/Tk application on an E3000, with 50+ instances running
simultaneously.
Abigail
--
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 12 Oct 1999 12:22:38 -0700
From: David Amann <dove@synopsys.com>
Subject: Re: Sending mail with Perl?
Message-Id: <38038A7E.658F374B@synopsys.com>
Hi Ewald,
Ewald Wasscher wrote:
> I use a slightly modified version
> of your script, but the script takes a long time and no mail is sent.
> See the modified script and the mailserver's log below. Got any idea
> what causes my problem? The same problem occurs when I use another
> mailserver.
I tried running the script and the only problem I got was with the -T. I
got the error "too late to use taint". Once I removed that and changed the
sender to me, all worked well.
You might make sure you have the latest versions of Net::SMTP and
Mail::Mailer.
(I'm using version 2.10 of Net::SMTP and version 1.17 of Mail::Mailer.)
Try getting them from your closest CPAN mirror, or if you are using
ActivePerl try the ppm.exe applicaiton.
Hope this helps,
-=dav
------------------------------
Date: Tue, 12 Oct 1999 12:58:18 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Slideshow script
Message-Id: <Pine.GSO.4.10.9910121257310.19155-100000@user2.teleport.com>
On Tue, 12 Oct 1999 jongunn@my-deja.com wrote:
> How can I make Netscape(NS) show one page at a time of the slideshow.
It sounds as if you want to get a browser to do something. Perhaps you
should search for the docs, FAQs, and newsgroups about browsers. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 12 Oct 1999 11:52:00 -0700
From: Shubro Mandal <shubro@topservice.com>
Subject: Typeglob bug?
Message-Id: <38038350.37E28B48@topservice.com>
From the perldata manpage:
=========================
The main use of typeglobs in modern Perl is create symbol table aliases.
This assignment:
*this = *that;
makes $this an alias for $that, @this an alias for @that, %this an alias
for %that, &this an alias for &that, etc. Much safer is to use a
reference. This:
Trouble:
========
#!/usr/bin/perl
$O = "dollar_O\n";
@O = ("OO", "bb", "\n");
*a = *O;
print "@O";
print "@a";
This program does not compile. This is the error message.
---
cruise<smandal>275: perl a.pl
In string, @a now must be written as \@a at pll line 6, near "@a"
Execution of pll aborted due to compilation errors.
cruise<smandal>276:
---
However, if I comment out the last line the program goes through
fine.
Any comments folks?
Thanks,
Shubro
------------------------------
Date: 12 Oct 1999 15:58:03 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Typeglob bug?
Message-Id: <x74sfwl5bo.fsf@home.sysarch.com>
>>>>> "SM" == Shubro Mandal <shubro@topservice.com> writes:
SM> $O = "dollar_O\n";
SM> @O = ("OO", "bb", "\n");
SM> *a = *O;
SM> print "@O";
SM> print "@a";
SM> This program does not compile. This is the error message.
SM> In string, @a now must be written as \@a at pll line 6, near "@a"
SM> Execution of pll aborted due to compilation errors.
interesting but not that difficult to explain. perl5 changed the
behavior of array vars being interpolated in strings. if the array has
never been seen before by the compiler, it will assume that the
interpolated array is bogus and the @ should be escaped. in this case,
you made the alias but there nevers was any code using @a before the
print. if you just did a @a; or any code that used @a outside a string
it will work fine. a use vars qw(@a) before that code will work too.
perl has no idea when you typeglob alias *a that you will use @a so it
can't handle that. you have to be explicit with @a before it can be used
in a string.
the change in @a interpolation is documented in perltrap.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
www.sysarch.com ----- Perl Books: http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 12 Oct 1999 12:27:37 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: use strict
Message-Id: <Pine.GSO.4.10.9910121225150.19155-100000@user2.teleport.com>
On 11 Oct 1999, Jeff Zucker wrote:
> Also you might want "use diagnostics" although it is less important.
You should not "use diagnostics" in production code, although it's fine
during development. It adds around 500ms to an empty program's startup
time, at least on my machine. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 12 Oct 1999 13:42:16 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Using Perl to add line nums?
Message-Id: <x3yhfjw79xj.fsf@tigre.matrox.com>
Tom Briles <sariq@texas.net> writes:
> Ala Qumsieh wrote:
> >
> > lr@hpl.hp.com (Larry Rosler) writes:
> >
> > > In article <4287-380290B4-1@storefull-214.iap.bryant.webtv.net> on Mon,
> > > 11 Oct 1999 21:36:52 -0400 (EDT), KernelKlink@webtv.net
> > > <KernelKlink@webtv.net> says...
> > > > Is it possible to write a Perl script that will add line numbers to an
> > > > existing script by using the existing script as an argument? I would
> > > > want even the blank lines to be numbered, not just the lines with text
> > > > on them.
> > > >
> > > > Will Perl do this?
> > >
> > > Perl will do just about anything. In one line. :-)
> > >
> > > For Windows/DOS:
> > >
> > > perl -pe "printf '%3d ', $." foo.txt
> > >
> > > For Unix:
> > >
> > > perl -pe 'printf "%3d ", $.' foo.txt
> >
> > Larry, haven't you ever written a Perl program that is more than a
> > thousand lines long?
>
> I'd bet that he has...
>
> > I am sure a lot of people have done so, so why
> > put that limit on your little snippet? (Especially that you
> > use printf() to get a nicer format than print()).
> >
> > perl -pe 'printf "%8d ", $.' foo.txt
>
> There is no limit. The digit is a minimum field length. But then, I'm
> sure Ala knew that, given sufficient supply of caffeine.
Yeah. What I actually meant is that Larry went into the trouble of
using printf() instead of simply using
print $., " "
because (I assumed) he wanted to preserve the nice formatting of the
line numbers. With the 1000 lines limit, any line numbers above 1000
will not be properly formatted.
Of course "properly" is highly subjective.
--Ala
PS. I don't drink coffee. My supply of caffeine comes from chocolate
and Pepsi. Perhaps I should be expanding my sources. Any ideas?
PPS. Coke is *NOT* an option!
------------------------------
Date: Tue, 12 Oct 1999 12:56:42 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: using the 'foreach' loop to split a string
Message-Id: <Pine.GSO.4.10.9910121251580.19155-100000@user2.teleport.com>
On 12 Oct 1999, Pfash1 wrote:
> #!perl-w
Be sure to put a space before the first option: "perl -w".
> my @eachrecord;
> open (FH, 'demo.db');
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
> while (<FH>)
> {
> $/ = "-----------------------";
I think you want to set this outside of the loop.
> chomp;
> s/\n[ \t]+/ /g;
Maybe you want s/\s+/ /g here?
> push @records, $_;
> }
> close (FH);
>
> foreach $record(@records)
> {
> @string = split(/ /, $record);
> }
> print @string;
You don't want to replace @string every time through the loop. Maybe you
want to push the new values onto @string each time? Or maybe you want to
split the words when you first read the lines, instead of using @records
at all.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 12 Oct 1999 19:06:34 GMT
From: "Ryan Michaels" <RyanM019@rem0veThis.home.com>
Subject: Where to find Perl scripts?
Message-Id: <_ELM3.9217$Pf4.55133@news.rdc2.mi.home.com>
I'm learning Perl, and the best way I learn any programming language is by
looking at code that's already written and figuring it out. Are there any
websites that have bundles of free Perl scripts?
They can be as simple as 'print "hello world";'.. it doesn't matter. I just
need something to learn from.
Thanks in advance.
------------------------------
Date: Tue, 12 Oct 1999 12:26:06 -0700
From: David Amann <dove@synopsys.com>
Subject: Re: Where to find Perl scripts?
Message-Id: <38038B4D.9FDFEE9F@synopsys.com>
Hi Ryan,
Ryan Michaels wrote:
> I'm learning Perl, and the best way I learn any programming language is by
> looking at code that's already written and figuring it out. Are there any
> websites that have bundles of free Perl scripts?
>
> They can be as simple as 'print "hello world";'.. it doesn't matter. I just
> need something to learn from.
If you have a few bucks to spend, I would recommend buying the Perl Cookbook by
Tom Christiansen and Nathan Torkington. It's chock full of examples that you
can use over and over again. And it's organized in an easy-to-reference way.
I use it constantly.
Hope this helps,
-=dav
------------------------------
Date: Tue, 12 Oct 1999 18:37:47 +0000
From: "David L. Nicol" <david@kasey.umkc.edu>
Subject: working perl -pie workaround
Message-Id: <38037FFB.720D6C30@kasey.umkc.edu>
Can't use both inline editing switch (-i) and
script-as-command-line-arg switch (-e) at the same
time. When I try, i get told that there is no file
with the name of my script-as-command-line-arg.
A working workaround appears as the sig of this message,
but is this a problem which is going to be repaired in
Perl 6?
Is there a reason
perl -pie 's/oldstring/newstring/g' target-file
cannot work as I expect it to?
_______________________________________________________
David Nicol 816.235.1187 nicold@umkc.edu
echo s/\\bNichol\\b/Nicol/g>p; perl -pi p *
------------------------------
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 1052
**************************************