[13041] in Perl-Users-Digest
Perl-Users Digest, Issue: 451 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 18:07:25 1999
Date: Tue, 10 Aug 1999 15:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 10 Aug 1999 Volume: 9 Number: 451
Today's topics:
Re: <== Help with date sorting==> (Matthew Bafford)
Re: <== Help with date sorting==> (Larry Rosler)
Re: Are PerlApp and Perl2exe the same? <cassell@mail.cor.epa.gov>
BEGIN's in subs (Andrew Allen)
bug in 'unpack'? <avc@sanger.ac.uk>
Re: CHMOD function (Malcolm Ray)
Re: CHMOD function <stirling@banet.net>
Re: CHMOD function <stirling@banet.net>
Re: chop? Split? help? <USENET@questionexchange.com>
Re: DBI ODBC memory leak?? mcm1303@my-deja.com
Re: Known Issues with perl <cassell@mail.cor.epa.gov>
Re: list length (Derek Sherlock)
Moving a Perlscript from NT to LINUX <schmickl@magnet.at>
Re: NO-ONE USES PERLQT !!!!!!!!!!!!!!!!!!!!!??????????? <cassell@mail.cor.epa.gov>
Re: perl prog: Top site thingy.. <alex@kawo2.rwth-aachen.de>
Re: Reading the Online Documentation? <tchrist@mox.perl.com>
reference to object method <dchristensen@california.com>
Re: require mylib.pl <cassell@mail.cor.epa.gov>
Re: require mylib.pl <cassell@mail.cor.epa.gov>
Re: search and match <cassell@mail.cor.epa.gov>
Re: search and match <USENET@questionexchange.com>
Re: Simple Perl Parsing? <cfang@nwu.edu>
Re: Some (tricky?) regexp questions <alex@kawo2.rwth-aachen.de>
Re: Sorting by mid-record without splitting? (Larry Rosler)
Re: Sorting by mid-record without splitting? <Monty.Scroggins@mci.com>
Re: Sorting by mid-record without splitting? <makkulka@cisco.REMOVETHIS.com>
Re: spelling of foobar (was Re: Reading the Online Docu (Dan Wilga)
Re: turn $6 into $6000 <markm@nortelnetworks.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 10 Aug 1999 21:09:17 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: <== Help with date sorting==>
Message-Id: <slrn7r14dr.d7g.*@dragons.duesouth.net>
On 10 Aug 1999 20:40:58 GMT, revjack <revjack@radix.net> spewed forth:
: Larry Rosler explains it all:
:
: :We have had in the past --
:
: :Germinal : mois où les plantes germent : month when plants germinate
: :Florial : mois des fleurs : month of flowers
: :Prairial : mois des prés : month of prairies
:
: [snip]
:
: Priantaire: mois de malsujet : month of newbie posts
Hmm, I thought September never ended?
--Matthew
------------------------------
Date: Tue, 10 Aug 1999 14:41:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: <== Help with date sorting==>
Message-Id: <MPG.121a3c55ceb01e5b989e21@nntp.hpl.hp.com>
In article <slrn7r13cp.d7g.*@dragons.duesouth.net> on Tue, 10 Aug 1999
20:57:17 GMT, Matthew Bafford <*@dragons.duesouth.net> says...
> And so it happened, on Tue, 10 Aug 1999 13:12:27 -0700, Larry Rosler)
> typed random characters into perl, and ended up with the following
> posted to comp.lang.perl.misc:
> : > my %months = (
> : > 'January' => 0, 'February' => 1, 'March' => 2,
> : > 'April' => 3, 'May' => 4, 'June' => 5,
> : > 'July' => 6, 'August' => 7, 'September' => 8,
> : > 'October' => 9, 'November' => 10, 'December' => 11, # just in case
> : > # we get more
> : > # months,
> : > # (JAL)R.
> : > );
> :
> : In any case, the slice is less to type, so less error-capable (that's
> : nicely alliterative in German: fehlerfähig):
As this deals with mistyping (aka the Fat Finger Syndrome), that could
have been 'fingerfehlerfähig'. In addition to being even more
alliterative, this is pleasingly agglutinative.
> : my %months;
> : @months{qw(
> : January February March April May June
> : July August September October November December
> : )} = (1 .. 12);
>
> And so much easier on the eyes!
Just in case we get more months, as you say,
my %months;
@months{qw(
January February March April May June
July August September October November December
Januar Februar März April Mai Juni
Juli August September Oktober November Dezember
)} = (1 .. 12, 1 .. 12);
where the duplicates will coalesce, of course.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 10 Aug 1999 14:35:08 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Are PerlApp and Perl2exe the same?
Message-Id: <37B09B0C.376F8AFC@mail.cor.epa.gov>
dakbat@hotmail.com wrote:
>
> The subject says it all. I have seen PerlApp on ActiveState's site and
> perl2exe on a seperate website (www.perl2exe.com). Are they the same?
> If not does anyone know the advantages/disadvantages of each? Thanks
They're not the same. They do have similar objectives.
I have read [unsubstantiated] rumors in the win32-perl-users
mailing list that perl2exe currently does a better job of coping
with large modules like CGI.pm , but that ActiveState is trying
to remedy that. YMMV.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 10 Aug 1999 21:03:33 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: BEGIN's in subs
Message-Id: <7oq435$n5j$1@fcnews.fc.hp.com>
Although perlref briefly mentions that "In the general case, then,
named subroutines do not nest properly, although anonymous ones do", I
was wondering why the following code behaves as it does:
sub a
{
my $c;
BEGIN {$c=7;}
print "c=$c\n";
}
a();
a();
prints out
c=7
c=
I'd expect either $c to always to be 7, or always to be undef.
Andrew
------------------------------
Date: Tue, 10 Aug 1999 22:14:10 +0100
From: "Tony Cox" <avc@sanger.ac.uk>
Subject: bug in 'unpack'?
Message-Id: <7oq3q4$ada$1@niobium.hgmp.mrc.ac.uk>
I'm running the same script on the same data file to grab some data from a
binary file on two different machines (both Linux/ix86):
Characteristics of this binary (from libperl): kernel version 2.2.10
Built under linux
Compiled at Apr 6 1999 23:34:07
@INC:
/usr/lib/perl5/5.00503/i386-linux
/usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.005
and
Characteristics of this binary (from libperl): kernel version 2.0.34
Built under linux
Compiled at Apr 21 1998 18:42:29
@INC:
/usr/local/lib/perl5/i486-linux/5.00404
/usr/local/lib/perl5
/usr/local/lib/perl5/site_perl/i486-linux
/usr/local/lib/perl5/site_perl
The code runs:
[snip]
$DWORD = 4
$sn_loc_offset = 12353
[snip]
open (IN, $filename) or die "Cannot open target data file: $!";
seek (IN,$sn_loc_offset,$DWORD);
$byte_count = read (IN, $snbuffer,$DWORD);
close (IN);
if ($byte_count){
$snbuffer = unpack("H8", $snbuffer);
$sn_offset = hex($snbuffer);
}
On one platform (5.00404) I get the correct answer for $sn_offset: 151995
On the other (5.00503) I get $sn_offset: 1094863174 (and my program blows
up)
Surely this can't be right? Any help or advice would be gratefully received.
thanks
Tony
------------------------------
Date: 10 Aug 1999 21:28:42 GMT
From: M.Ray@ulcc.ac.uk (Malcolm Ray)
Subject: Re: CHMOD function
Message-Id: <slrn7r16ca.ui9.M.Ray@carlova.ulcc.ac.uk>
On Tue, 10 Aug 1999 16:19:55 -0400, stirling@banet.net <stirling@banet.net>
wrote:
[snip - bogus solution changing single to double quotes]
> I assume that the Perl kernel's rules about using chmod on the file
>whose name is contained in
> the scalar are different,
Why assume? Have you read perlop yet? There is no possible way
for the chmod function to behave differently in these two cases.
It gets passed *exactly* the same argument in each case, because
there was no interpolation in your double-quoted string. There is
no deep magic at work here.
>anyway in a more roundabout way, my solution
>works. =-)
No it doesn't. Your code works if and only if the original
questioner's code works. Which it didn't, hence their question.
Their problem must lie elsewhere, and they've probably figured it
out by now from the other answers they received.
--
Malcolm Ray University of London Computer Centre
------------------------------
Date: Tue, 10 Aug 1999 17:39:25 -0400
From: <stirling@banet.net>
Subject: Re: CHMOD function
Message-Id: <37b09a6f@news1.us.ibm.net>
>Your solution is *only* different from the original poster's in that
>it's slower.
>
>It doesn't fix anything.
----And yet the funny thing is, it works. The way I came up with this
solution is that the original poster said that it worked without the
variable substitution, but didn't work with the variable substitution. I
had never seen anyone do it without double quotes, and I then *tested* this
to see if it was true before posting it on the newsgroups (what I think
everyone should do before posting solutions). This may be a Perl bug, but
it exists.
Thank You for challenging me,
Stirling Hughes
------------------------------
Date: Tue, 10 Aug 1999 17:40:32 -0400
From: <stirling@banet.net>
Subject: Re: CHMOD function
Message-Id: <37b09ae3@news1.us.ibm.net>
see reponse to Tom Briles
------------------------------
Date: 10 Aug 1999 21:47:36 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: chop? Split? help?
Message-Id: <731qx@questionexchange.com>
> I have got this to return a list of files in a directory but
> what I was trying to figure out is how I can remove the .txt
> or whatever from the end of each. I have tried to figure it out
> but I really am just shooting in the dark and nothing seems to
> work. I wanted to end up putting it into a link later on like
> http://www.blah.com/cgi-bin/@allfiles[0] I tried split, chop,
> s/// ,but I hardly know what they do I'm learning every thing
> from other peoples code and it is slow going. if can point me
> in the right direction thank you! peek@gci.net this prints out
> the files. opendir BUSDIR, "$basepath$pagedir" || die "Unable
> to open directory: $!"; @allfiles = readdir BUSDIR; closedir
> BUSDIR; ######## had to shift it twice to get rid of . and ..
> don't know if this is right but it worked? ##### shift
> @allfiles; shift @allfiles; print "@allfiles\n";
Use an s/// expression like the following to remove the
extension on a filename: $filename = "blah.txt"; $filename
=~ s/\..*$//; print "$filename\n"; # will print 'blah' The
"\." matches the '.' that the extension starts with. The ".*"
matches anything up to the "$", which marks the end of the
line. If you want to do this to all of the files in @allfiles
at once, and you're using Perl 5, you can use the map command
as follows: map(s/\..*$//, @allfiles); shifting twice to get
rid of "." and ".." is probably not the best thing to do,
because they might not be there or might be in a different
place. You could do something like this to solve your overall
problem: opendir BUSDIR, "$basepath$pagedir" || die "Unable to
open directory: $!"; @allfiles = readdir BUSDIR; closedir
BUSDIR; foreach $file (@allfiles) { ($file eq '.' || $file
eq '..') && next; $file =~ s/\..*$//; $link =
"http://www.blah.com/cgi-bin/$file"; # now do whatever you
want # with $link }
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2495&cus_id=USENET&qtn_id=1675
------------------------------
Date: Tue, 10 Aug 1999 21:28:21 GMT
From: mcm1303@my-deja.com
Subject: Re: DBI ODBC memory leak??
Message-Id: <7oq5h8$59$1@nnrp1.deja.com>
In article <7on2te$o0m$1@nnrp1.deja.com>,
mmixon@primacis.com wrote:
> In article <dwilgaREMOVE-0608991555570001@wilga.mtholyoke.edu>,
> dwilgaREMOVE@mtholyoke.edu (Dan Wilga) wrote:
> > > All I'm doing is executing several thousand $dbh->prepare +
> > > $dbh->execute statements to perform SQL selects. The MSSQL
> temporary
> > > database on the server just grows and grows until it runs out of
> disk
> > > space...
> > >
> > > Also experimented using the $sth->finish, thinking that might
help,
> but
> > > the problem persists.
> > >
> > > Any ideas? Many Thanks -- Marlin Mixon
> >
> > You may need to do a $dbh->commit from time to time, if
> $dbh->{AutoCommit}
> > is off. It should be on by default, though.
> >
> Thanks for the reply, Dan. That isn't the problem as I have not
changed
> autocommit. I did try sneaking a $db->commit in there anyway, but all
I
> get are warning messages that say "commit ineffective with Autocommit
> enabled" and then the same problem of the tempdb expanding out of
> control.
>
> I suppose one workaround I could use is to break the processing up
into
> smaller batches, but that's a pain. Any other workaround solutions?
I solved the problem by working around it. Since I'm working in a Win32
environment, I also have Win32::ODBC available. I made the switch and
never looked back. As a bonus, I discovered that, in my case,
Win32::ODBC is about ten times faster than DBI::ODBC!
Marlin Mixon
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 10 Aug 1999 14:33:11 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Known Issues with perl
Message-Id: <37B09A97.E4CF07FF@mail.cor.epa.gov>
Seshu Adunuthula wrote:
>
> Are there any resources to check for known issues with perl
> specifically on NT, (Bug fixes between different releases) etc.
You could check the resources provided by ActiveState with each
install of ActiveState Perl. Specifically, there are several
sections of the ActivePerl [win32] FAQ which discuss umm, urr,
'features' of the win32 port.
> I am running into problems with perl on NT. version 5.004_01
Have you considered upgrading to 5.005_03 , the current stable
version? It's simple to download from ActiveState, and it
in essence installs itself.
> specifically with running shell scripts from within a perl CGI
> script
>
> open (FD, "c:\\temp\\foo.bat | ");
> while (<FD>)
> {
> print;
> }
>
> The above script worked for most part and failed after a long
> regress. Now perl refuses to execute the command foo.bat and
> I am not sure where to start investigating.
See if Perl can run foo.bat from the command line. If so,
then it looks like a webserver problem. You might want to
take a look at the first question in perlfaq9 [section 9
of the core Perl FAQ], which should be on your machine if
you have Perl there. If not, you can get it for free, with
minimal effort.. so go to it.
> (Rebooting the @#$% NT is not an option :-( )
Sorry to hear that. But it may be something other than
Perl, in which case you'll have to do *something*.
> Does perl have any dependencies on any registry variables
> that could potentionally have gotten corrupted during the
> long regress?
This is also mentioned in the ActivePerl FAQ. And Perl
has win32-specific modules for dinking with the registry
as well.
Good luck,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 10 Aug 99 21:18:08 GMT
From: derek_sherlock@hp.com (Derek Sherlock)
Subject: Re: list length
Message-Id: <rr15og.1btkt1d@bogomip.fc.hp.com>
Hi,
My bad -- trying to infer a general principle where none exists!
Under my earlier (mistaken) misconception, the second line of
following output would have been 3. In fact it is 12, since
the comma operator in a scalar context returns only it's right
hand arguement.
sub thing { return (1,2,12) }
print "@{[&thing]}\n";
print scalar(&thing),"\n";
Produces the output:
1 2 12
12
Thanks for deconfusifying me.
Derek.
Nearly 934393604 seconds after the Epoch, merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Derek" == Derek Sherlock <derek_sherlock@hp.com> writes:
>
> Derek> If you access a list in a scalar context, you get the number of
> Derek> elements.
>
> I suppose that may be hypothetically true. But that would be just as true
> as "If you access a list in a scalar context, you get PI accurate to
> 20 places."
>
> Because both of them have a false premise.
>
> LISTS do not exist in a scalar context. Ever.
>
> $n = @a; # no list here, just the number of elements of array @a
> $n = grep /foo/, @b; # no list here, just the number of hits
> $n = getpwnam 'merlyn'; # no list here, just the user ID number
> $n = /foo/g; # no list here, just a true/false value if it matches
> $n = <FOO>; # no list here, just the next chunk read from FOO, or undef
> $n = ($a,$b,$c); # no list here, just value of $c after discarding $a and $b
>
> Get the picture?
>
> THERE CANNOT BE A LIST IN A SCALAR CONTEXT. EVER.
>
> And to jump back to this thread, the value of Thread->list in a scalar
> context is entirely up to the author of the list() method, and could
> be entirely unrelated to what that same construct does in a list
> context. If you want the number of elements of that list-context return
> value, one easy way is:
>
> $count = () = Thread->list;
>
> But that's hacky. :) Better to read the docs and see if there's a useful
> scalar value for Thread->list.
>
> print "Just another Perl hacker,"
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 10 Aug 1999 23:44:33 +0200
From: Thomas Schmickl <schmickl@magnet.at>
Subject: Moving a Perlscript from NT to LINUX
Message-Id: <37B09D40.1F94FB6@magnet.at>
Hi, I started my project with Perl & Perl/Tk to write an application
that runs unchanged on different OS.
But now I tried to release the first version of it and noticed the
following bad thing:
I developed with WinNT and packed the *.pl and *.pm -files with my
compression programm ... fine.
Then I restarted the computer with LINUX, looked at my files and
arghh...
First I transformed them with "recode ibmpc:latin1 *.pl" into
unix-textfiles, but
I unfortionatly used german special characters in my code.
So I know, this is not a pure PERL-question, but I think many of you
guys/girls
here might have had this problem before.
Maybe you can give me a hint ???
------------------------------
Date: Tue, 10 Aug 1999 14:41:10 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: NO-ONE USES PERLQT !!!!!!!!!!!!!!!!!!!!!?????????????????????????
Message-Id: <37B09C76.6285BC69@mail.cor.epa.gov>
Pavel Ravits wrote:
[a complete absence of content]
Perhaps no one uses PERLQT because there is no such thing.
Maybe PerlQT exists, but that's not the same.
If you have a question about programming in Perl, then perhaps
this newsgroup is a reasonable place to post. If so, then
please follow the directions in the autobot e-mail you should
have received from gnat. Otherwise, you'll just get yourself
plonked at the speed of light. I can already hear Abigail
pressing that oversized 'K' on Abigail's keyboard...
HAND,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 10 Aug 1999 23:29:12 +0200
From: Alex Farber <alex@kawo2.rwth-aachen.de>
Subject: Re: perl prog: Top site thingy..
Message-Id: <37B099A8.A4490F15@kawo2.rwth-aachen.de>
Hi David,
David Cassell wrote:
> I don't want to dissuade you from answering, but do you
> *really* want to be making guesses in a newsgroup with TomC
> and Abigail and Uri and LarryR ? :-)
well I have a different attitude to comp.lang.perl.misc as probably some
of these guys. I see this newsgroup more as a brainstorming. My replies
should not be perfect or even correct - there is still a chance that they
will help someone who stuck with his code.
Regards
Alex
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Koeln, Aachen oder Umgebung.
------------------------------
Date: 10 Aug 1999 16:02:54 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Reading the Online Documentation?
Message-Id: <37b0a18e@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
mesarchm@aol.com (Mesarchm) writes:
:He answers 90% of the posts on this newsgroup w/ "Read the Docs"
And well he should. 90% of the answers are there. Expect to be
slapped if you don't read there first.
: Get a life. If you have nothing better to do then sit around all day and not
:help people then you really need to get out and get a life.
I already did help people. That's why I wrote so many of the docs.
Now, kindly read them all and don't come back from AOL hell until
you do.
RTFM is *always* the right answer for people who haven't done so.
--tom
--
People who deal with bits should expect to get bitten. --Jon Bentley
------------------------------
Date: Tue, 10 Aug 1999 14:29:29 -0700
From: "David Christensen" <dchristensen@california.com>
Subject: reference to object method
Message-Id: <37b09772@news5.newsfeeds.com>
Hello, World!
I have started working with Perl objects, and am stuck:
How do I create a reference to an object method?
How do I dereference the reference?
For example, let's say I have a script, foo.pl:
#!/fsf/bin/perl -w
use Bar;
my $bar = new Bar();
And I have a module, bar.pm:
package Bar;
# constructor
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless ($self, $class);
return $self;
}
# function
sub FooOnYou {
$self = shift;
print @_;
}
1; # use
Calling the object method directly works:
$bar->FooOnYou("Howdy\n");
~/code/perl/foo$ ./foo.pl
Howdy
When I attempt to create and use a reference to the object method:
my $ref = \$bar->FooOnYou;
&$ref("Howdy\n");
~/code/perl/foo$ ./foo.pl
Not a CODE reference at ./foo.pl line 11.
Or this way:
my $ref = \{$bar->FooOnYou};
&$ref("Howdy\n");
~/code/perl/foo$ ./foo.pl
Not a CODE reference at ./foo.pl line 11.
Or this:
my $ref = \&bar->FooOnYou;
&$ref("Howdy\n");
~/code/perl/foo$ ./foo.pl
Undefined subroutine &main::bar called at ./foo.pl line 10.
And several others...
Can it be done? What's the syntax?
TIA,
--
David Christensen
dchristensen@california.com
-----------== 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, 10 Aug 1999 14:22:46 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: require mylib.pl
Message-Id: <37B09826.536F1F52@mail.cor.epa.gov>
Nick Downey wrote:
>
> The perl cookbook would lead me to believe that perhaps I should learn how
> to write a module because the notion of libraries is quickly becoming
> obsolete, however, all I want to do is store a mass of strings...
Well, the notion of libraries has noticeable limitations when
you begin using multiple require() statements and/or you have a
require() in something with a require() which in turn has...
So modules are convenient. And not that hard to use either.
> const.pl:
> $const_str1 = 'this is string1';
> $const_str2 = 'this is string2';
>
> 1;
Okay, since you have The Perl Cookbook, go back and re-read
section 12.1 to see what you left out. You'll want to stick in
the standard header bits so you can *export* your symbols.
That said, if you really want constants, you ought to use the
'constant' pragma. Here's a dirty example using the above:
package MyConst.pm;
use strict;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw/ CONST_STR1 CONST_STR2 /;
@EXPORT_OK = qw/ CONST_STR3 /;
use constant CONST_STR1 => 'your string here';
use constant CONST_STR2 => 'another string';
use constant CONST_STR3 => 'optional string constant';
1;
> #// const.pl
>
> mytest.pl
> #!/usr/bin/perl -w
>
> require 'const.pl';
use lib '.'; #tell Perl where to find your module
use MyConst; #now you have the first two constants available
#"use MyConst qw(:DEFAULT CONST_STR3);"
# would get the optional constant too
> print "$const_str1\n";
> print "$const_str2\n";
> #// mytest.pl
>
> Now, if there is anything that I have learned from reading this group it is
> that you must use the -w flag. So I use said flag and the following output
> is sent to stderr accordingly:
>
> Name "main::const_str1" used only once: possible typo at ./mytest.pl line
> 5.
> Name "main::const_str2" used only once: possible typo at ./mytest.pl line
> 6.
Right. Your symbols weren't exported. Perl was wondering
what the heck you were up to.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 10 Aug 1999 14:25:03 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: require mylib.pl
Message-Id: <37B098AF.C5A9605C@mail.cor.epa.gov>
Kvan wrote:
[snip]
> Firstly, you could do what you've been doing, but use a hash instead
> of separate strings. Secondly, you could make a module. How to do this
Oddly enough, that was what the poster was trying to do.
> is detailed in the Camel, or if you lack such a beast:
And he was trying to work from the Ram too, which has quite a
lot of detail on this topic.
HAND,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 10 Aug 1999 14:37:56 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: search and match
Message-Id: <37B09BB4.EC2C16CB@mail.cor.epa.gov>
Christian Evans wrote:
[I moved Eric's response up where it should be]
> Eric Bohlman <ebohlman@netcom.com> wrote in message
> news:7opn33$occ@dfw-ixnews3.ix.netcom.com...
> > Christian Evans (chris.evans@tc.faa.gov) wrote:
> > : print "$_">OUT_FILE;
> > This is most likely your problem. You're trying to write awk code in
> > Perl. The above line means "treat the current value of $_ as a number.
> > Compare it numerically with the filehandle OUT_FILE. Print '1' to STDOUT
> > if it's greater, or '0' otherwise."
> >
> > In Perl, what you want is:
> >
> > print OUT_FILE $_;
> >
> > which can be simplified to:
> >
> > print OUT_FILE;
> that didnt work...the print OUT_FILE i mean
It works for me. Perhaps you need to show us your new code
so we can evaluate it.
Oh, BTW, please post in standard usenet order, so that it
is easier for everyone to follow the thread. Thank you.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 10 Aug 1999 21:47:28 GMT
From: QuestionExchange <USENET@questionexchange.com>
Subject: Re: search and match
Message-Id: <730qx@questionexchange.com>
> I have a module in a perl script that allows users to search
> for a record with a field that matches a desired date. The
> dates are in the format with the first three letter of the
> month (i.e. Jan) followed by one OR two spaces, and the day of
> the month. How can I write the script to search for all
> possible records. I have tried many different possible choices
> and can't seem to get any of them to work. It seems as though
> when I search, my script will match all records with a field
> with a given month, but I can't seem to match the month and the
> date at the same time. Thanks
You should be doing something like this: (starting with the
month in $month and day in $day): $month = "Nov"; $day =
"23"; while(<>) { # or whatever if(/$month ?$day/) { #
got a match. } }
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/servlet1/showUsenetGuest?ans_id=2496&cus_id=USENET&qtn_id=1669
------------------------------
Date: Tue, 10 Aug 1999 16:05:44 -0500
From: "Chao Fang" <cfang@nwu.edu>
Subject: Re: Simple Perl Parsing?
Message-Id: <7oq48j$d89@news.acns.nwu.edu>
$line =~ /(STARThello worldEND)/;
print $1;
Linux GNUBEE <dchurch@kabana.net> wrote in message
news:7optnf$2ov$1@macaw.cyberport.com...
> Could someone please show me how to grab ONLY certain text from a string,
> such as the following:
>
> my $line = "fasdjfhkdfhaksdfhSTARThello worldENDaskjkdfljkdfjls";
>
> How can I parse out only the text between the two tags, including the tags
> in their respective positions within the string. In other words, I want
> toend up with
>
> STARThello worldEND
>
> Thanks.
>
> dan :)
>
>
>
------------------------------
Date: Tue, 10 Aug 1999 23:58:44 +0200
From: Alex Farber <alex@kawo2.rwth-aachen.de>
To: marcza@my-deja.com
Subject: Re: Some (tricky?) regexp questions
Message-Id: <37B0A094.7BBD2BE1@kawo2.rwth-aachen.de>
Hi Marcus,
marcza@my-deja.com wrote:
> How do I match only those lines which have a 4-digit year or a
> 4-digit-year-slash-4-digit-year on second position (delimited by
> space(s)) AND put the result in a $1 variable ?
try
/ ( [012]\d\d\d (?: \/ [012]\d\d\d )? ) /x
Regards
Alex
PS: run "perldoc perlre"
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Koeln, Aachen oder Umgebung.
------------------------------
Date: Tue, 10 Aug 1999 14:16:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting by mid-record without splitting?
Message-Id: <MPG.121a36a6786a784c989e20@nntp.hpl.hp.com>
In article <37b4759d.527933037@news.iinc.com> on Tue, 10 Aug 1999
19:04:45 GMT, Effie Rover <null@effierover.com> says...
> I have a database, pipe-delimited, which I read from a file into an
vertical-bar separated and terminated!
> array (because it's read from two files and mashed together based on
> flags, not because I want to take up the extra memory).
One can sort indexes without having all the data in memory, but that
takes a little work.
> Once I have my array, I want to sort it by the third field in the
> record, i.e. here's a sample of my database:
... <reproduced below>
> I already know how to split records, pull fields and either build a
> hash or another array with the key field in front for sorting. Isn't
> there a Perl construct to sort these without splitting? I thought
> there was, but I pored over 'sort' in all my available resources
> (book, docs, faq and Deja) and can't find a solution without building
> an extraneous hash. Or maybe I'm just not understanding the code
> correctly.
You have somehow to break out the field to sort on, either by substr or
unpack (if fixed widths), or by split or regex. In this case, split
seems natural. It will actually require two splits, or a split and an
unpack.
And the results have to be stored somewhere, in addition to the original
data (or index into a list -- see my comment above). But you don't need
an 'extraneous hash', though that's one of several possibilities. See
also the Schwartzian Transform (which uses anonymous arrays) or the
packed-default sort (which uses concatenated strings -- see
<URL:http://www.hpl.hp.com/personal/Larry_Rosler/sort/>). Here is the
latter (which is, of course, the fastest) written as a long 'one-liner':
#!/usr/local/bin/perl -w
use strict;
print map substr($_, 8) =>
sort
map
join("" => (unpack 'A2xA2xA4' => (split /\|/)[3])[2, 0, 1], $_)
=> <DATA>;
__END__
1|Effie's Birthday|effie|10/07/1999|||||||Owner's Birthday|
2|Basqual's Birthday|basqual|10/14/1999|||||||The Mighty Ranger|
3|Micah Jackson at Pyramid Games|micah|08/09/1999||08:00 pm cdt|||||Gen
Con Wrap!|
4|INWO Summer Leagues|sue|08/12/1999||06:00 pm cdt|||||INWO games|
You can, of course, use temporary variables in a block to work out the
details of the sortkey extraction. The way above is the most 'fun'.
...
> Dwoemers sent in the vile tongue of Redmond may be given as ritual
> sacrifice to the void faerie. (Don't send me HTML formatted email)
HTML isn't the vile tongue of Redmond. Try Visual Basic or several
others. But it is vile in Usenet, nevertheless!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 10 Aug 1999 21:30:52 GMT
From: "Monty Scroggins" <Monty.Scroggins@mci.com>
Subject: Re: Sorting by mid-record without splitting?
Message-Id: <gS0s3.1224$8X1.111249@PM01NEWS>
Check out the Sort-Fields package on CPAN
The auther is JNH..
It does exactly what you are asking for..
Monty
Effie Rover <null@effierover.com> wrote in message
news:37b4759d.527933037@news.iinc.com...
>
> Perl Gurus:
>
> I have a database, pipe-delimited, which I read from a file into an
> array (because it's read from two files and mashed together based on
> flags, not because I want to take up the extra memory).
>
> Once I have my array, I want to sort it by the third field in the
> record, i.e. here's a sample of my database:
>
> 1|Effie's Birthday|effie|10/07/1999|||||||Owner's Birthday|
>
> 2|Basqual's Birthday|basqual|10/14/1999|||||||The Mighty Ranger|
>
> 3|Micah Jackson at Pyramid Games|micah|08/09/1999||08:00 pm
> cdt|||||Gen Con Wrap!|
>
> 4|INWO Summer Leagues|sue|08/12/1999||06:00 pm cdt|||||INWO games|
>
>
> [Newsreader wrapped some lines]
>
> I already know how to split records, pull fields and either build a
> hash or another array with the key field in front for sorting. Isn't
> there a Perl construct to sort these without splitting? I thought
> there was, but I pored over 'sort' in all my available resources
> (book, docs, faq and Deja) and can't find a solution without building
> an extraneous hash. Or maybe I'm just not understanding the code
> correctly.
>
> Many thanks in advance for a quick pointer or a No.
>
> -- Loy
>
> Loy Ellen Gross AKA Effie Rover -- effie @ effierover . com
> The email address above goes straight to /dev/null :-)
> Effie Rover's Fantasy RPG Library -- http://www.effierover.com
> ------------------------------------------------------------------
> Dwoemers sent in the vile tongue of Redmond may be given as ritual
> sacrifice to the void faerie. (Don't send me HTML formatted email)
>
------------------------------
Date: Tue, 10 Aug 1999 14:33:59 -0700
From: Makarand Kulkarni <makkulka@cisco.REMOVETHIS.com>
Subject: Re: Sorting by mid-record without splitting?
Message-Id: <37B09AC7.38FEBA02@cisco.REMOVETHIS.com>
[
Monty Scroggins wrote:
> Check out the Sort-Fields package on CPAN
> The auther is JNH..
> It does exactly what you are asking for..
]
But it still splits the records for the sort to happen.
--
------------------------------
Date: Tue, 10 Aug 1999 17:20:58 -0400
From: dwilgaREMOVE@mtholyoke.edu (Dan Wilga)
Subject: Re: spelling of foobar (was Re: Reading the Online Documentation?)
Message-Id: <dwilgaREMOVE-1008991720580001@wilga.mtholyoke.edu>
In article <37B08B35.58916CC@chaos.wustl.edu>, elaine@chaos.wustl.edu wrote:
> Uri Guttman wrote:
>
> > i once read great history of the term foo and its cousins including other
> > name holders from around the world. does anyone know the link?
>
> Metasyntactic variable :)
>
> http://www.netmeg.net/jargon/terms/m/metasyntactic_variable.html
Interesting list. I have always used the sequence "foo, bar, baz, boop".
Don't know where I picked up "boop" from.
Dan Wilga dwilgaREMOVE@mtholyoke.edu
** Remove the REMOVE in my address address to reply reply **
------------------------------
Date: 10 Aug 1999 17:07:54 -0400
From: Mark Mielke <markm@nortelnetworks.com>
Subject: Re: turn $6 into $6000
Message-Id: <lq1d7wv4a51.fsf@bmers31f.ca.nortel.com>
Uri Guttman <uri@sysarch.com> writes:
> >>>>> "AQ" == Ala Qumsieh <aqumsieh@matrox.com> writes:
> AQ> Elaine -HFB- Ashton <elaine@chaos.wustl.edu> writes:
> >> Uri Guttman wrote:
> >> > print $money ;
> >> > i have always wanted to print money.
> >> Well, you always could...as long as you weren't counterfeiting US
> >> currency which would grab the attention of the Secret Service. :)
> AQ> Hmmm .. so Canadian money is ok to counterfeit?
> sure. it is worth the same as monpoly money. and remember, we are at war
> with canada (see the south park movie) so counterfeiting their money is
> patriotic.
Now now... your dollar is only worth $1.5x CDN... :-)
And we don't have transparent necks or polygonic faces as South Park
would have you believe... :-)
mark
--
markm@nortelnetworks.com/mark@mielke.cc/markm@ncf.ca __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | CUE Development (4Y21)
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | Nortel Networks
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada
One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...
http://mark.mielke.cc/
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 451
*************************************