[10758] in Perl-Users-Digest
Perl-Users Digest, Issue: 4359 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 4 13:07:25 1998
Date: Fri, 4 Dec 98 10:00:21 -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 Fri, 4 Dec 1998 Volume: 8 Number: 4359
Today's topics:
"insecure" variables? (123) <snowe@rain.org>
ARP? or How to get MAC address? (Scott Steeves)
auto submitting a form? <doconner@copper.ucs.indiana.edu>
Re: auto submitting a form? <Tony.Curtis+usenet@vcpc.univie.ac.at>
big problem with Perl's time() limitations (Andreas Schildbach)
Re: big problem with Perl's time() limitations (Sean McAfee)
Bug in timelocal? <seen@statoil.com>
Re: Bug in timelocal? (Clinton Pierce)
Re: Can standard Perl functions be overloaded ? (Sean McAfee)
Re: Can standard Perl functions be overloaded ? (Sean McAfee)
CGI and LWP::Simple <doug@weboneinc.com>
Re: Creating a key field for writing relational databas <newsposter@cthulhu.demon.nl>
Does latest version of Perl have POSIX for NT? <dwc3q@cs.virginia.edu>
Embedded Perl and C <richard.swift@kanatek.ca>
Fastest way to search through an array? (Jason C. Hill)
Re: Fastest way to search through an array? <ebohlman@netcom.com>
Re: Fastest way to search through an array? (Tad McClellan)
Re: File with Sendmail <daniel@boksjo.com>
Re: is it possible to use perl for win as a CGI <nospam.xnera@cyberenet.net>
Re: newbie file open question <nospam23_skidoo@geocities.com>
Re: newbie file open question (Tad McClellan)
Re: newbie file open question (Tad McClellan)
Newbie needs help with regex in perl script! (RemarQ User)
Re: Newbie needs help with regex in perl script! <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: oraperl (John D Groenveld)
Re: Perl on Solaris 2.5.1 (#!/opt/LWperl/bin)? droby@copyright.com
Pretty Printing Perl rdosser@my-dejanews.com
R.E Perl script <en02@gre.ac.uk>
Re: the Unix epoch is not the beginning of time (was Re (I R A Aggie)
Re: usage of $_ within nested loops <merlyn@stonehenge.com>
Re: Variable modification in module without "return"? sam@tregar.com
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 4 Dec 1998 08:44:00 -0800
From: Nick Halloway <snowe@rain.org>
Subject: "insecure" variables? (123)
Message-Id: <Pine.SUN.4.05.9812040833560.9223-100000@coyote.rain.org>
I'm trying to run a perl script through procmail. It's being run by a
mail server. Mail goes to procmail; the .procmailrc pipes the mail
to a /bin/sh script which defines some environment variables then calls
the perl version 5.004_02 script.
It bombs like this:
procmail: Executing "modenv_test,/home/snowe/submission"
Insecure $ENV{PATH} while running setgid at
/home/snowe/stump/admin/bin/submission line 35.
procmail: Program failure (255) of "modenv_test"
Line 35 looks like:
`env >>/home/members/w/wesson9/junk1`;
So,
What does "running setgid" mean? Does it mean the process doesn't have
a user ID assigned, only a group ID?
If so, how could I find out where the user ID got lost? Normally procmail
would set the user ID of the process.
Can I get the .procmailrc to tell me what user ID it's running with?
Can I get a /bin/sh script to tell me what user ID it's using? I tried
"getuid" and "geteuid" but it doesn't recognize those commands.
Can I get the perl script to tell me what user ID it's using?
Is the lack of a user ID what would cause those "insecure variable"
messages?
Thanks.
------------------------------
Date: Fri, 04 Dec 1998 15:11:24 GMT
From: steevess@shore.net (Scott Steeves)
Subject: ARP? or How to get MAC address?
Message-Id: <36674df6.28085849@news.shore.net>
I really hope that I've done enough searching and haven't missed
something stupid, but...
Is there any module that has a routine that I can use to determine
the MAC address of a remote system? I'm looking for ARP, basically.
I did find a couple routines that shell to run a system command,
but I was hoping to do it entirely within Perl.
Thanks in advance,
Scott
------------------------------
Date: 4 Dec 1998 17:17:04 GMT
From: The Irishman <doconner@copper.ucs.indiana.edu>
Subject: auto submitting a form?
Message-Id: <7495eg$pvv$2@jetsam.uits.indiana.edu>
I'm having my mail filtered and mail with the subject 'sendpage' is
forwarded off to my perl script. I then extract out the 'from' field and
the 'message' and disgard the rest of the header information. Now I
need to have the two variables sent to an external script on my phone
companies webserver automatically.
Is it possible for perl to auto submit forms?
thanks for any help.
me
------------------------------
Date: 04 Dec 1998 18:54:27 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: auto submitting a form?
Message-Id: <833e6v23os.fsf@vcpc.univie.ac.at>
Re: auto submitting a form?, The
<doconner@copper.ucs.indiana.edu> said:
The> header information. Now I need to have the two
The> variables sent to an external script on my
The> phone companies webserver automatically.
The> Is it possible for perl to auto submit forms?
Obviously yes, otherwise browsers wouldn't be able
to do it.
=> perldoc LWP
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: Fri, 04 Dec 1998 16:11:27 GMT
From: andreas.schildbach@rkdnet.de (Andreas Schildbach)
Subject: big problem with Perl's time() limitations
Message-Id: <366907c9.17179022@news.mediaways.net>
Hello,
I've got a problem with Perl's time()-format limitations, mainly being
able to express only dates starting at 1.1.1970.
I want to store birthdates in that format, but due to the above
limitation this is not possible.
Can anyone point me to an alternative that meets the following
requirements:
1) can express date AND time in one scalar (like time does).
2) ranges from <1900 to >2050 (the more the better).
3) minimum resolution: seconds, but 1/10 or 1/100 of a second would be
better (for other purposes than the birthdates, of course... :-)
4) a minimum set of utility functions with functionality equal or
greater than those included in the perl-package (timelocal,
localtime).
Thanks for any information!
- Andreas
------------------------------
Date: Fri, 04 Dec 1998 16:50:23 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: big problem with Perl's time() limitations
Message-Id: <jpU92.115$4w2.416293@news.itd.umich.edu>
In article <366907c9.17179022@news.mediaways.net>,
Andreas Schildbach <andreas.schildbach@rkdnet.de> wrote:
>I've got a problem with Perl's time()-format limitations, mainly being
>able to express only dates starting at 1.1.1970.
This isn't true; although it doesn't meet all of the conditions you specify
below, you can get dates before 1970 by using negative numbers. Try this:
perl -le 'print scalar localtime(-2**30)'
>Can anyone point me to an alternative that meets the following
>requirements:
>1) can express date AND time in one scalar (like time does).
>2) ranges from <1900 to >2050 (the more the better).
>3) minimum resolution: seconds, but 1/10 or 1/100 of a second would be
>better (for other purposes than the birthdates, of course... :-)
>4) a minimum set of utility functions with functionality equal or
>greater than those included in the perl-package (timelocal,
>localtime).
The first place to look would be CPAN; there are a number of date-related
modules available.
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Fri, 04 Dec 1998 16:04:37 +0100
From: Your Real Name <seen@statoil.com>
Subject: Bug in timelocal?
Message-Id: <3667FA05.85133474@statoil.com>
Hello!
The documentation for Time::Local explicitly states that the timelocal()
routine is guaranteed to agree with localtime(). Ie the seconds value
put into localtime() should be the seconds value received from
timelocal() on the corresponding arguments.
However, when I tried this out, there were some mismatches...:-(
The code I used looks like this:
use Time::Local;
$step = 900;
$begin = 100000;
#$begin = 909000000;
$end = time;
for ( $i = $begin ; $i <= $end ; $i += $step ) {
@arr = localtime( $i );
@_ = @arr[ 0 .. 5 ];
$val = timelocal( @_ );
if ( $i != $val ) {
$time = sprintf( "%02d.%02d:%02d %02d.%02d.%02d",
$_[2], $_[1], $_[0], $_[3], $_[4]+1, $_[5] );
print " $i: $time -> $val\n";
}
}
That is, I run localtime() on quite a number of different time values.
For each of the lists returned, I pick out the 6 first elements, and use
them as arguments to timelocal(). If the returned value is different
from the initial one, I print it in a readable way.
Since I basically loop through "the whole time universe" since 1970
until today, it takes a while,
and it tests all values in 15 minutes intervals (900 seconds as step
value). However, there are quite a few mismatches. They all appear at
night, between 2 AM and 3 AM, and there is one hour each year that
reports the mismatch. I have deleted quite a few in the middle from the
full output here:
243993700: 02.01:40 25.09.77 -> 243997300
243994600: 02.16:40 25.09.77 -> 243998200
243995500: 02.31:40 25.09.77 -> 243999100
243996400: 02.46:40 25.09.77 -> 244000000
276048100: 02.01:40 01.10.78 -> 276051700
276049000: 02.16:40 01.10.78 -> 276052600
276049900: 02.31:40 01.10.78 -> 276053500
276050800: 02.46:40 01.10.78 -> 276054400
...
877824100: 02.01:40 26.10.97 -> 877827700
877825000: 02.16:40 26.10.97 -> 877828600
877825900: 02.31:40 26.10.97 -> 877829500
877826800: 02.46:40 26.10.97 -> 877830400
909273700: 02.01:40 25.10.98 -> 909277300
909274600: 02.16:40 25.10.98 -> 909278200
909275500: 02.31:40 25.10.98 -> 909279100
909276400: 02.46:40 25.10.98 -> 909280000
To test it locally, just use the big $begin value that is currently
commented out, it should return the last 4 values if you have the same
problem as I do.
I don't dare using this code in production work until why this happens.
The difference reported is always 3600, ie an hour.
I have run this on Perl 5.004_03 on a Solaris 2.5.1 box, on an IRIX 6.5
box, on a SunOS 4.1.4 box, on an HP-UX 10.20 machine (the same Perl
version on all). They all had the same problem.
The date command returns Fri Dec 4 15:53:02 MET 1998 . I am
situated in Norway, so the time zone is quite non-american...:-)
Regards,
Stein-Erik
------------------------------
Date: Fri, 04 Dec 1998 16:01:32 GMT
From: cpierce1@mail.ford.com (Clinton Pierce)
Subject: Re: Bug in timelocal?
Message-Id: <366d06b9.78816337@news.ford.com>
[Courtesy CC sent to poster in E-Mail]
On Fri, 04 Dec 1998 16:04:37 +0100, Your Real Name <seen@statoil.com>
wrote:
>However, when I tried this out, there were some mismatches...:-(
>
>[...]
>
>Since I basically loop through "the whole time universe" since 1970
>until today, it takes a while,
>and it tests all values in 15 minutes intervals (900 seconds as step
>value). However, there are quite a few mismatches. They all appear at
>night, between 2 AM and 3 AM, and there is one hour each year that
>reports the mismatch. I have deleted quite a few in the middle from the
>full output here:
"Between 2AM and 3AM" and "one hour each year"
*ahem*
Does your area observe Daylight Savings time?
------------------------------
Date: Fri, 04 Dec 1998 16:55:37 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Can standard Perl functions be overloaded ?
Message-Id: <duU92.116$4w2.418595@news.itd.umich.edu>
In article <912778772.858727@thrush.omix.com>,
Zenin <zenin@bawdycaste.org> wrote:
> He didn't ask about CORE::open(), he asked about open(), which is
> quite easy to redefine:
> # Foo.pm
> package Foo;
> require 'Exporter';
> @EXPORT = 'open'
>
> sub open (*$) {
> do my open stuff
> }
> 1;
>
> # foo
> use Foo 'open';
> open FOO, "some_file.or.whatever.txt";
Or, if you don't want the hassle of creating a separate file:
use subs 'open';
sub open { ... }
I did this recently with die:
use Carp;
use subs 'die';
*die = \&Carp::croak;
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Fri, 04 Dec 1998 17:17:11 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Can standard Perl functions be overloaded ?
Message-Id: <rOU92.118$4w2.429561@news.itd.umich.edu>
In article <duU92.116$4w2.418595@news.itd.umich.edu>, I wrote:
>Or, if you don't want the hassle of creating a separate file:
>use subs 'open';
>sub open { ... }
On further investigation, it appears that one can't have a subroutine
prototype when using this kind of construct:
use subs 'open';
sub open (*$) { ... }
With Perl 5.005, I get this error message:
Prototype mismatch: sub main::open vs (*$) at -e line 1.
Bummer.
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Fri, 04 Dec 1998 10:55:06 -0500
From: Douglas Clifton <doug@weboneinc.com>
Subject: CGI and LWP::Simple
Message-Id: <366805DA.9C4356CB@weboneinc.com>
When I use both modules in a script:
use CGI qw(:standard);
use LWP::Simple qw(head);
I get the following error/warning from Perl [v5.00404]:
Prototype mismatch: sub main::head vs ($) at [snip]
Which I assume means the method head() is defined in
both CGI and LWP::Simple. Should I undef head before
I `use' LWP::Simple?
Thanks,
--
Douglas Clifton
Unix/C/Perl/CGI/HTML Programmer
doug@weboneinc.com
------------------------------
Date: Fri, 04 Dec 1998 11:39:22 -0500
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Creating a key field for writing relational databases
Message-Id: <36681039.AA0D8381@cthulhu.demon.nl>
Mark Thompson wrote:
>
> Hi,
>
> I'm rewriting a program that now writes to a simple text file so that it will
> create 2 tables for importing into a database.
>
> Basically, the two files will be a customer file and a parts ordered file.
> Obviously to link them I need a unique key field.
>
> Does anyone have any suggestions on how to generate a key field value on the
> fly in Perl? I'm using 5.005 if that makes any difference. Anything pretty
> much goes as long as it can guarantee that there are no duplicates. I've
> seen stuff combining the process id and the date/time but I was wondering if
> there were any better methods (plus, I don't know if this is foolproof.)
This isn't really a perl-specific question, but a database question:
Table 1 (customer)
cust_id name address etc...
Table 2 (order)
id id2 cust_id
The tables are linked through the cust_id field
cust_id is your unique key for customer
id|id2 is your unique key for order
So for customer 25 you would number the orders as follows:
id id2 product
25 1 shoes
25 2 jeans
This doesn't answers your question the way you stated it, but I think this is
what you need.
Erik
------------------------------
Date: Fri, 4 Dec 1998 10:05:08 -0500
From: David Coppit <dwc3q@cs.virginia.edu>
Subject: Does latest version of Perl have POSIX for NT?
Message-Id: <Pine.WNT.4.03.9812040956091.237-100000@legacy.cs.virginia.edu>
I'd like to use POSIX for formatting of time and date information, but
users said it wasn't supported on NT. I heard that the latest version does
support it, but the release notes for 5.005 said that posix.t fails
sometimes.
What's the scoop? Is there an NT Perl that is POSIX compliant with respect
to the date stuff, and if so, which version(s)?
Thanks,
David
_________________________________________________________________________
David Coppit - Graduate Student coppit@cs.virginia.edu
The University of Virginia http://www.cs.virginia.edu/~dwc3q
"For I am a Bear of Very Little Brain,
and long words Bother me" - Winnie the Pooh
------------------------------
Date: Fri, 04 Dec 1998 08:53:57 -0500
From: Richard Swift <richard.swift@kanatek.ca>
Subject: Embedded Perl and C
Message-Id: <3667E975.9DA828E5@kanatek.ca>
Hi,
I've successfully embedded the perl interpreter in my C program and now
I'm stuck on what to do next. All of the examples in the docs seem to
work by reading in perl scripts from files or executing functions
without actrually showing how the function was loaded.
What I would like to be able to do is have the C program
compose(possible quite complex) perl programs on the fly and then pass
them as some sort of character array, array of pointers to strings, etc.
to the interpreter. Has anyone done this. Could you provide a simple
example in code?
I know I can write the perl program out to a tmp file and then read it
back in but this seems overly messy to me and I would rather avoid this
approach if at all possible.
Thanks in advance,
Richard
------------------------------
Date: Thu, 03 Dec 1998 20:55:07 GMT
From: jhill22@csc.com (Jason C. Hill)
Subject: Fastest way to search through an array?
Message-Id: <3666f99e.1411156635@news.csc.com>
I currently have a setup where I'm reading through a file that has
around 10k entries max, and about 2k entries minimum. I'm searching
for a specific string in the entries.
I have 2 arrays, 1 temporary array, and 1 master array.
This is the procedure
sub compare_pop_users {
$count_var = 0;
for ($i = 0; $i < @pop_user; $i++) {
for ($j = 0; $j < @master_list; $j++) {
if (@master_list[$j] eq @pop_user[$i]) {
$count_var = 1;
} #end if
} #end inner for
if ($count_var == 0) {
push @master_list, @pop_user[$i];
} else {
$count_var = 0;
} #end if
} #end outter for
} #end sub compare_pop_users
It's a simple search and compare double for loop.
I'm looking for something either more powerful or quicker than this.
This entire thing can be iterated over with the amount of entries
being from 2 to 10k anywhere from 30 to 360 times.
I think part of the speed problem right now is that the files are
gzip'd and they need to be gunzip'd and read through. However,
anyplace that I can help speed up the process the better.
Thanks,
-Jason C. Hill
------------------------------
Date: Fri, 4 Dec 1998 15:25:00 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Fastest way to search through an array?
Message-Id: <ebohlmanF3G5Ho.Dsn@netcom.com>
Jason C. Hill <jhill22@csc.com> wrote:
: I currently have a setup where I'm reading through a file that has
: around 10k entries max, and about 2k entries minimum. I'm searching
: for a specific string in the entries.
: sub compare_pop_users {
: $count_var = 0;
: for ($i = 0; $i < @pop_user; $i++) {
: for ($j = 0; $j < @master_list; $j++) {
: if (@master_list[$j] eq @pop_user[$i]) {
: $count_var = 1;
: } #end if
: } #end inner for
: if ($count_var == 0) {
: push @master_list, @pop_user[$i];
: } else {
: $count_var = 0;
: } #end if
: } #end outter for
: } #end sub compare_pop_users
: It's a simple search and compare double for loop.
Which is an inherently slow algorithm. Fortunately, Perl provides a
powerful solution to this type of problem: hashes. The following should
work as a drop-in replacement for your code and should be a *lot* faster,
though you could speed it up even further by rethinking some of your data
structures (which I can't do, not knowing how @master_list and @pop_user
are used in other parts of your code).
sub compare_pop_users {
#create a hash whose keys are the elements of @master_list and whose values
#are any defined value (1 for convenience)
my %temp = map {$_,1} @master_list;
#add as keys all elements of @pop_user. The hashing process will avoid
#duplication
@temp[@pop_user] = 1 x @pop_user;
#turn the hash back into an array of elements
@master_list = keys %temp;
}
This code does depend on one assumption: that the order of entries in
@master_list is unimportant.
------------------------------
Date: Fri, 4 Dec 1998 12:14:06 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Fastest way to search through an array?
Message-Id: <ep8947.j19.ln@metronet.com>
Jason C. Hill (jhill22@csc.com) wrote:
: if (@master_list[$j] eq @pop_user[$i]) {
^ ^
^ ^
Isn't -w complaining about those array slices there?
You should be using -w on *all* of your perl scripts.
You should ask for a scalar if you want a scalar:
if ($master_list[$j] eq $pop_user[$i]) {
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 4 Dec 1998 15:39:04 +0100
From: "Daniel Boksjv" <daniel@boksjo.com>
Subject: Re: File with Sendmail
Message-Id: <3667f4b9.0@d2o62.telia.com>
I mean I've only been programming basic PERL before...
/Daniel
------------------------------
Date: Fri, 04 Dec 1998 09:46:44 -0500
From: Xnera <nospam.xnera@cyberenet.net>
Subject: Re: is it possible to use perl for win as a CGI
Message-Id: <3667F5D4.69CE930C@cyberenet.net>
Glen
I've successfully used perl with PWS for NT Workstation. I haven't
gotten around to setting it up at home (where I'm running Win98 as
well. =) ), but I don't see why it wouldn't work there as well.
The trick is setting up your server to run perl when it encounters
scripts
with extensions .pl or .cgi. There is a a help file at
www.microsoft.com
that tells you how to do this. I don't remember the title of the
document,
and I have to search a bit for it everytime I look there. Do some
searching on 'perl and cgi'.
If you set up your PWS and then install perll, some part of the perl
setup will set up your PWS for you.
Off the top of my head, this is what I remember:
run 'Internet Service Manager'
right-click on the folder and select properites
click on 'configuration...'
Add -> (these are the settings I have:)
Executable = <your perl path here>Perl.exe %s %s
Extension = .pl
Method = PUT,DELETE (don't know what this is for)
Check that file exists is checked.
but this only sets it up for certain directories. At my last job,
I had it set up to run in all the virtual directories, but I can't
remember
what I did to do that.
Hope this helps.
Karen
g l e n r a m s e y wrote:
> if so can someone enlighten me :-)
>
> i can quite happily use perl in my "batch files", i simply can't use
> them through a browser as a CGI
>
> (i'm using PWS under windows95 --well, actually ''98, ut don't tell
> anyone)
>
> thanks
>
> ~glen.
------------------------------
Date: Fri, 04 Dec 1998 15:10:12 +0000
From: 23_skidoo <nospam23_skidoo@geocities.com>
Subject: Re: newbie file open question
Message-Id: <3667FB52.1A02@geocities.com>
> One problem: Your code did this:
> foreach $line (@lines) {
> ...
> $line++;
>
> This probably won't work right, because $line contains both
> the number and a newline, so (strictly speaking) it's not a
> number, and who know what ++ will do to it? It's a bit more
> code, but it'd be safer to pull the number out:
> if (($num,$rest) = ($line =~ /^(\d+)(.*)/)) {
> $line = ++$num . $rest;
> }
> This will increment the first number if $line starts with
> a number, and leave the rest of the line unchanged.
>
> <insert perl mantra "There's more than one way to do it" here>
chanting that mantra as i go, could i not just chomp($line) ? perl is
pretty forgiving about being handed a string and treating it as a number
isn't it? or is that a 'doable but that doesn't mean you should do it'
thing? (newbie perl hacker but i've been reading the word crufty a lot
round here, never felt the need to ask what it meant as it seemed pretty
self evident :)
-23
------------------------------
Date: Fri, 4 Dec 1998 12:07:59 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie file open question
Message-Id: <vd8947.j19.ln@metronet.com>
23_skidoo (nospam23_skidoo@geocities.com) wrote:
: > One problem: Your code did this:
: > foreach $line (@lines) {
: > ...
: > $line++;
: >
: > This probably won't work right, because $line contains both
: > the number and a newline, so (strictly speaking) it's not a
: > number, and who know what ++ will do to it?
++ wants a number, so perl will convert the string to a number.
converting a number to a string ignores leading whitespace,
and ignores trailing nonnumerics (newline is a nonnumeric).
[
The above is stated at the bottom of page 39 in "Learning Perl".
But the footnote at the bottom of page 40 says that -w will
give a warning. It doesn't with 5.00404 or 5.00502??
I can't find a description of how strings are converted to
numbers in either "Programming Perl" nor in the PODs for
5.00502. Is that a bug in the documentation, or am I just
not searching for the right words?
I thought is said somewhere that perl uses C's atoi() for
converting strings to numbers, but I cannot find anywhere
that says that now either...
]
: > It's a bit more
: > code, but it'd be safer to pull the number out:
: > if (($num,$rest) = ($line =~ /^(\d+)(.*)/)) {
: > $line = ++$num . $rest;
: > }
: > This will increment the first number if $line starts with
: > a number, and leave the rest of the line unchanged.
^^^^^^^^^^^^^^^^^^^^^^^^^^
No it won't.
$line won't have a newline at the end like it did at the beginning.
So the result is the same as the code given up there at the top...
: >
: > <insert perl mantra "There's more than one way to do it" here>
: chanting that mantra as i go, could i not just chomp($line) ? perl is
: pretty forgiving about being handed a string and treating it as a number
: isn't it? or is that a 'doable but that doesn't mean you should do it'
: thing? (newbie perl hacker but i've been reading the word crufty a lot
: round here, never felt the need to ask what it meant as it seemed pretty
: self evident :)
chomp()ing would also be fine.
------------------------
#!/usr/bin/perl5.00502 -w
print "### let perl do the conversion:\n";
$line = "12\n";
print "before: '$line'\n";
$line++;
print "after: '$line'\n\n";
print "### somebody's way (the attribution is missing):\n";
$line = "12\n";
print "before: '$line'\n";
if (($num,$rest) = ($line =~ /^(\d+)(.*)/)) {
$line = ++$num . $rest;
}
print "after: '$line'\n\n";
print "### fixed somebody's way:\n";
$line = "12\n";
print "before: '$line'\n";
if (($num,$rest) = ($line =~ /^(\d+)(.*)/s)) { # m//s to not lose the newline
$line = ++$num . $rest;
}
print "after: '$line'\n";
print "### using chomp():\n";
$line = "12\n";
print "before: '$line'\n";
chomp($line);
$line = $num++ . "\n"; # put the newline back in
print "after: '$line'\n";
------------------------
output:
### let perl do the conversion:
before: '12
'
after: '13'
### somebody's way (the attribution is missing):
before: '12
'
after: '13'
### fixed somebody's way:
before: '12
'
after: '13
'
### using chomp():
before: '12
'
after: '13
'
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 4 Dec 1998 12:34:23 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie file open question
Message-Id: <fv9947.a79.ln@metronet.com>
Tad McClellan (tadmc@metronet.com) wrote:
: ++ wants a number, so perl will convert the string to a number.
: converting a number to a string ignores leading whitespace,
^^^^^^^^^^^^^^^^^^
Uhhh.
That should be "string to a number" of course...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 04 Dec 1998 09:11:53 -0800
From: james.huff@sierra.com (RemarQ User)
Subject: Newbie needs help with regex in perl script!
Message-Id: <1VU92.241$45.372772@WReNphoon1>
Hi everyone. I'm a newbie to perl so I will get right to it.
I would like to insert some text (from STDIN) at the *beginning* of _every_
individual line.
so if I had the line bar .... I would like to be able to insert foo before
it. As such: foobar.
The problem is that I do not know (and don't care) what the first character
of line is. I just want to insert
the text on every line at the beginning.
Here is what I have so far. Obviously, it doesn't work or I would be writing
this.
open (LOGFILE, $filetofix);
while ($lines = <LOGFILE>)
{
$lines =~ s/^/$inserttext/;
}
close (LOGFILE);
I have also tried s/[^./i]/$inserttext/
Can anyone help me out here. These files are apx. 25 MB a piece and I
__really__ don't want to copy and
paste each one.
TIA,
James H.
james.huff@sierra.com
-**** Posted from remarQ, Discussions Start Here(tm) ****-
http://www.remarq.com/ - Host to the the World's Discussions & Usenet
------------------------------
Date: 04 Dec 1998 18:57:49 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Newbie needs help with regex in perl script!
Message-Id: <831zmf23j6.fsf@vcpc.univie.ac.at>
Re: Newbie needs help with regex in perl script!,
RemarQ <james.huff@sierra.com> said:
RemarQ> Hi everyone. I'm a newbie to perl so I will
RemarQ> get right to it. I would like to insert
RemarQ> some text (from STDIN) at the *beginning* of
RemarQ> _every_ individual line.
# glommed from STDIN
$prefix = 'foo';
while (<FILE>) {
print $prefix;
print;
}
close(FILE) or die ....;
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: 4 Dec 1998 12:18:27 -0500
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: oraperl
Message-Id: <7495h3$j73$1@tholian.cse.psu.edu>
Tons of Oracle on Linux information recently posted to comp.databases.oracle.*
The Perl modules DBI and DBD::Oracle are available from http://www.cpan.org/
Also take a look at Apache and mod_perl
John
groenveld@acm.org
------------------------------
Date: Fri, 04 Dec 1998 16:44:42 GMT
From: droby@copyright.com
Subject: Re: Perl on Solaris 2.5.1 (#!/opt/LWperl/bin)?
Message-Id: <7493hl$dsg$1@nnrp1.dejanews.com>
In article <ltemqi8naq.fsf@asfast.com>,
Lloyd Zusman <ljz@asfast.com> wrote:
> Casper.Dik@Holland.Sun.Com (Casper H.S. Dik - Network Security Engineer)
writes:
>
> > Aleksandar Milivojevic <alex@srce.hr> writes:
> >
> > ># ln -s /opt/LWperl/bin/perl /usr/bin/perl
> >
> > >Usualy, perl scripts either expect to find /usr/bin/perl or have some
> > >wired paths so you'll have to change them anyway.
> >
> > That's why I like:
> >
> > #!/usr/bin/env perl
> >
> > best. (As long as perl is in your PATH, it works)
>
> The only pitfall is that on a few OS's that support the `#!'
> mechanism, you cannot have any arguments following `perl' on that
> line.
>
Actually, there can be other pitfalls, depending on what else is in PATH.
You do want to make sure people invoking your script get the real perl and
not some imitation. ;->
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 04 Dec 1998 15:19:44 GMT
From: rdosser@my-dejanews.com
Subject: Pretty Printing Perl
Message-Id: <748uic$9aj$1@nnrp1.dejanews.com>
I'd like to pretty print my perl code from Red Hat Linux. I remember using
vgrind years ago, but can only find it for Debian. I've got Tom C's
vgrindefs.perl, but without vgrind itself it's kind of worthless.
Anybody have any thoughts?
Thanks,
Ralph Dosser
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 04 Dec 1998 14:59:00 +0000
From: Neil Elliott <en02@gre.ac.uk>
Subject: R.E Perl script
Message-Id: <3667F8B4.EB823179@gre.ac.uk>
Cheers all for your help althought I have managed to fix the script by
bining it and using a combnation of cgi and java.
Thanks for your help anyway
Neil Elliott
The University of Greenwich
en02@gre.ac.uk
http://www.gre.ac.uk/~en02
------------------------------
Date: Fri, 04 Dec 1998 09:50:35 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: the Unix epoch is not the beginning of time (was Re: localtime () - perl's bug ?)
Message-Id: <fl_aggie-0412980950350001@aggie.coaps.fsu.edu>
In article <19981203.205235.8a5.rnr.w164w_-_@locutus.ofB.ORG>, Russell
Schulz <Russell_Schulz@locutus.ofB.ORG> wrote:
+ lr@hpl.hp.com (Larry Rosler) writes:
+
+ > I don't understand why someone changed the title of this thread
+
+ yes, you've demonstrated that you don't understand. you seem rather
+ comfortable in that lack of understanding, though.
Its an understanding that is useless.
No, really.
0 according to the Hebrew reckoning isn't the beginning of time.
0 according to the Mayan reckoning isn't the beginning of time.
0 according to the Celtic reckoning isn't the beginning of time.
0 according to the astronomer's reckoning isn't the beginning of time.
And yet, each of those reckoning's serve their purpose well. The unix
epoch is Just Another Reckoning. It serves its purpose well.
Its purpose is not to count all seconds since the beginning of time,
but from a specified reference point.
James
------------------------------
Date: Fri, 04 Dec 1998 15:28:57 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: usage of $_ within nested loops
Message-Id: <8cogpk9b9v.fsf@gadget.cscaper.com>
>>>>> "Gareth" == Gareth Rees <garethr@cre.canon.co.uk> writes:
Gareth> However, the various looping constructs that implicitly assign
Gareth> to $_: `while', `for', `foreach', `until', `grep', 'map'
Gareth> automatically localize $_:
No. No.
foreach does (if that's the variable you're using to walk through the
list). grep does. map does. The others use the outer $_.
Witness:
$ perl
$_ = "outer\n";
print "before: $_";
open F, "date|";
while (<F>) { print "inside: $_"; }
print "after: $_\n";
^D
before: outer
inside: Fri Dec 4 08:27:29 MST 1998
after:
$
Yup. $_ got clobbered.
print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Fri, 04 Dec 1998 15:48:43 GMT
From: sam@tregar.com
To: jdavis@osprey.arc.nasa.gov
Subject: Re: Variable modification in module without "return"?
Message-Id: <74908r$ark$1@nnrp1.dejanews.com>
In article <3666D24C.A1F919A9@osprey.arc.nasa.gov>,
Jennifer Davis <jdavis@osprey.arc.nasa.gov> wrote:
> I want to have a module modify a non-global variable.
> I don't want the variable to be returned via "return"
> because I am using return for my success/failure codes
> (and eventually I might want to modify more than one
> non-global variable). (I'm trying to use pass-by-
> reference as I do in C. Perhaps I can't do this in
> Perl?)
Simple answer - there is *NO* automatic de-referencing of reference types in
Perl. This is different than C and C++. See below for the needed changes:
> Here is the jist of what I'm doing:
>
> local $x = "";
> $result = b::a(\$x);
> print "$x"; # this results in the null string
>
> b.pm has:
>
> a()
> {
> $pkg = shift;
> $x = shift;
>
> $x = "bubba";
>
> print "$x"; # this results in "bubba"
You just overwrote your REFERENCE to $::x with the string "bubba"! What you
really wanted was:
$ref_to_x = shift;
$$ref_to_x = "bubba";
I believe this will work as expected. Feel free to email me if it doesn't - I
have a couple other ideas that might help. I've only ever used call-by-ref in
perl with arrays and hashes for which I use the more obvious $ref->[] or
$ref->{} syntax.
-sam
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 4359
**************************************