[9642] in Perl-Users-Digest
Perl-Users Digest, Issue: 3236 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 23 15:07:23 1998
Date: Thu, 23 Jul 98 12:01:41 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 23 Jul 1998 Volume: 8 Number: 3236
Today's topics:
Re: Is Perl y2k compliant? (Andre L.)
Re: Is Perl y2k compliant? (Craig Berry)
Is Perl Year 1999 Compliant??? John_Cavanaugh@NOSPAM.hp.com
Is there a better way to do this? <Richard@waveney.demon.co.uk>
Re: is there a isNumber($aString) function? ((null))
Last Name First... (Al Gordon)
Re: Last Name First... (Al Gordon)
Re: local %ENV buggy with open <maraism@sterlingdi.com>
Re: modifying a text file <jdf@pobox.com>
Re: modifying a text file <simonf@conduit.co.uk>
Re: modifying a text file (Craig Berry)
MsDev Automation with Perl eoloughlin@my-dejanews.com
Re: Multiple Key Sort (M.J.T. Guy)
Re: Multiple Key Sort (Abigail)
Re: Multiple Key Sort <maraism@sterlingdi.com>
Newbie punctuation question <markstang@ncgroup.com>
Re: Pattern Matching Snafus <matt@whiterabbit.co.uk>
Perl CGI image and text problem <ferguson@viz.tamu.edu>
question about the @_ variable <larryq@nospam.tuttle.com>
Re: question about the @_ variable <jdporter@min.net>
Re: question about the @_ variable (Larry Rosler)
Re: References as strings <maraism@sterlingdi.com>
Re: Regexp Help/Perl Help (Steve Linberg)
Re: Regexp Help/Perl Help <simonf@conduit.co.uk>
Re: result pending code..? <jpratt@command-central.nmsd.k12.nm.us>
Re: sort email list <tonylabb@infonline.net>
Re: sort email list <simonf@conduit.co.uk>
Re: STUMPED!!! (perl trivia) <maraism@sterlingdi.com>
Re: su function <frankie@etsetb.upc.es>
Re: what is the difference between "tie" & "dbmopen"? (M.J.T. Guy)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 23 Jul 1998 13:19:08 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Is Perl y2k compliant?
Message-Id: <alecler-2307981319080001@dialup-909.hip.cam.org>
In article <6p7g7h$njk$1@nnrp1.dejanews.com>, huntersean@my-dejanews.com wrote:
> In article <6p5kj7$mkn$5@marina.cinenet.net>,
> cberry@cinenet.net (Craig Berry) wrote:
> > Victor O. (vonyemelukwe@att.com) wrote:
> > : Is Perl y2k?
> >
> > No, it's not. We'll all be out of work in 17 months, and most of the Web
> > will come crashing down, too. It's not going to be pretty.
> >
>
> Either you don't know what you're talking about, or you're joking.
[Darn serious reply snipped.]
No, _you_ gotta be kidding!
A.L.
------------------------------
Date: 23 Jul 1998 18:05:22 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Is Perl y2k compliant?
Message-Id: <6p7u12$d1l$2@marina.cinenet.net>
huntersean@my-dejanews.com wrote:
: In article <6p5kj7$mkn$5@marina.cinenet.net>,
: cberry@cinenet.net (Craig Berry) wrote:
: > Victor O. (vonyemelukwe@att.com) wrote:
: > : Is Perl y2k?
: >
: > No, it's not. We'll all be out of work in 17 months, and most of the Web
: > will come crashing down, too. It's not going to be pretty.
:
: Either you don't know what you're talking about, or you're joking.
Every time I think I've hit a situation where smileys *definitely* won't
be needed to make it plain I'm joking, something like this happens. So:
:) :) :)
: The web will not come crashing down, neither will the world end, and there
: will not be a plague of locusts o'er the land.
I'm going to hold you to that prediction, you know. Especially the
locusts part.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 23 Jul 1998 17:59:35 GMT
From: John_Cavanaugh@NOSPAM.hp.com
Subject: Is Perl Year 1999 Compliant???
Message-Id: <6p7tm7$cf4@canyon.sr.hp.com>
Am I the only one on the planet terribly concerned about year 1999
compliance. Doest every company have a group working on this.
Ok. This was just a stress relieving post to humorize all the incredibly
stupid posts I have seen in this newsgroup.
-----------------------------------------------------------------------
John Cavanaugh Hewlett-Packard Company
Project Engineer 1400 Fountaingrove Pkwy
EESof Division Santa Rosa, CA 95403-1799
Email: cavanaug@sr.hp.com Phone: 707-577-4780
707-577-3948 (Fax)
-----------------------------------------------------------------------
The ancestor of every action is a thought.
-- Ralph Waldo Emerson
-----------------------------------------------------------------------
------------------------------
Date: Thu, 23 Jul 1998 19:01:16 +0100
From: Richard Proctor <Richard@waveney.demon.co.uk>
Subject: Is there a better way to do this?
Message-Id: <ant2318160b0Rr9i@waveney.demon.co.uk>
Is there a better way to do this?
Its Perl, so the answer is Yes!
Context: in the middle of a script that is doing on the fly modification of
html being fetched from other servers (with the owners permission) using LWP,
munged and then sent on again to the end user. It apparently works but I am
unhappy with this bit of it.
$Buffer contains the current chunk of data roughly 4K, $NextBuffer contains
the next chunk, I always have two chunks in hand and ensure that $Buffer does
not contain split markup, which is fine for all the munging apart from this
one element of change. The original data is not very well organised for
splitting into clear records, though the final result is clear enough on the
screen.
The bit that I was concerned about is essentially doing "Does string X
appear before string Y, given that either might be in this Chunk, or the
next Chunk?"
I have added some additional comments to make the code clearer (I hope I have
not added too many bugs).
#lots of other code before
$Buffer =~
s!\$?\<a href\=\"[^"]*ordform\.html\"\>[(\s\$]*? #order form up to first $
(?: # 2 or 1 prices?
(?:([.0-9]+)\/[\s\w()-]*?\$([.0-9]+)) #2 prices
|
(?:([.0-9]+).{0,20}?\&) # Single price includes a '&'
).{0,15}?\<\/a\>! { # trailer junk to </a>
# This match is horrible but works, the data is not very consistent
# This garantees a warning, but makes the following code more readable
# it would be nicer to embed this within the regex as in (?$USPrice=...)
$Warn=$^W;$^W=0;
$USPrice = $1;
$OtherPrice = $2;
$OnePrice = $3;
$^W=$Warn;
# Amount is the single price if there is one, the US price if
# special order node 1, otherwise (90%+) the "OtherPrice"
if ($OnePrice) { $Amount = $OnePrice }
else {
($Ahead) = split (/ordform\.html/i, $' . $NextBuffer );
# Set Ahead to string up to next ordform
$Amount = (($Ahead =~ /spec(-|\%2d)ord.{0,40}Note\s*\#\s?1/i )
? $USPrice : $OtherPrice);
# Here is the messy does "Ahead" contain special order note #1
};
sprintf(" %s%1.1f0 %s ",$Currency,$Amount*1.1/$ConvertRate + 0.05,
($& =~ /\(each\)/)?" (each) ":"")
} !gisex;
# lots more follows
Let the debate begin...
--
Richard Proctor
for(0..119){($/*=2)+=ord(substr'NAJE&$KW#RJPTHD IP,^',$_%5+5*int$_/30)>>
$_/5%6&1;if($_%5>3){print$/?chr$/+($%?96:64):' ';$%=$/;$/=0}}
------------------------------
Date: 23 Jul 1998 18:27:46 GMT
From: mike@stok.co.uk ((null))
Subject: Re: is there a isNumber($aString) function?
Message-Id: <6p7vb2$6b3@news-central.tiac.net>
In article <6p6tv5$3np$1@nnrp1.dejanews.com>, <dwiesel@my-dejanews.com> wrote:
>Hi,
>
>How can I tell if a string (e.g. "7945797945") is a number or not?
If you have a recent installation of perl then
perldoc perlfaq4
should display section 4 of the FAQ (frequently asked questions) which
contains this question and its answer (near the end...)
How do I determine whether a scalar is a number/whole/integer/float?
If your system doesn't have the perlfaq documentation instaleed then visit
http://www.perl.com and follow the FAQs link.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Thu, 23 Jul 1998 18:01:16 GMT
From: al@ioa.com (Al Gordon)
Subject: Last Name First...
Message-Id: <35b7785a.643405@news.ioa.com>
Gurus, help!
I have a text tab-delimeted file that follows a format something like
this:
field 1<tab>field 2<tab>field 3<tab> ... etc.
The third field contains names of businesses and individuals.
Businesses might be something like: "Joe Smith Corp." (without the
quotes) and individuals are listed like "Smith, Joe" or "Smith, Joe
W." (again, without the quotes).
I need to convert the "lastname, firstname" formatted text in the file
to "firstname lastname" (both without quotes). The business names in
the third field will not contain commas (or at least I hope they
don't).
I know that Perl is the perfect tool for the job, but I'm not
proficient enough in it to knock out what should be a simple task.
Anyone feel like helping out? It'd be appreciated. I'm against a
deadline to get this done today, so that the file can be converted and
imported into a customer database. :P
Thanks in advance.
------------------------------
Date: Thu, 23 Jul 1998 18:06:58 GMT
From: al@ioa.com (Al Gordon)
Subject: Re: Last Name First...
Message-Id: <35b77b64.1421754@news.ioa.com>
On Thu, 23 Jul 1998 18:01:16 GMT, al@ioa.com (Al Gordon) wrote:
>I need to convert the "lastname, firstname" formatted text in the file
>to "firstname lastname" (both without quotes). The business names in
>the third field will not contain commas (or at least I hope they
>don't).
Okay, some business names in that field contain the string ", Inc.",
so that'll have to be taken care of. I'm sure if I could get my
eyeballs on some code to get me started, I could put that bit in
without a problem.
------------------------------
Date: Thu, 23 Jul 1998 14:09:42 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: local %ENV buggy with open
Message-Id: <35B77C66.62D2D980@sterlingdi.com>
> hi perl gurus,
>
> This doesn't seems to be a FAQ (at least I do not found any clues anywhere).
> And this is my 2nd posting for this Q? Maybe the question is too stupid so
> that nobody want to waste time answering it, or maybe it is too tricky and
> nobody have enough competence to answer it ...?
>
> From a perl script I'm trying to launch another script w/ open but I want to
> set my own ENV for this script, but setting ENV after redeclaring it as local
> doesn't seems enough for open:
>
> This little script illustrate what I want to do and what happen actualy...
>
> ---8x-----try-it.pl----
> #!/usr/local/bin/perl
>
> my $level = $ARGV[0];$level++;
>
> exit if $level > 2;
>
> sub printenv {
> while ( my ($k, $v) = each %ENV ) {
> print "$level> $k \t=> \t$v\n";
> }
> }
>
> my %MY_ENV = ( 'MY_K1' => 'K1_VAL' );
>
> # here %ENV contain the values of environ
> printenv;
>
> {
> local %ENV = %MY_ENV;
> # here %ENV contain the values of %MY_ENV
> # which is the expected behavior
> printenv;
>
> open( ENVX, "$0 $level |" ) or die "$0 $level | ... BOOM!";
> # the %ENV printed here is NOT the value contained
> # in the `local' %ENV
> while ( <ENVX> ) {
> print;
> }
> close ENVX;
> }
> #---end of try-it.pl -------
>
> As a turnaround I can use the following hack:
>
> my ($k, $v);
> foreach $k ( keys %ENV ) {
> delete $ENV{ $k };
> }
> while ( my ($k, $v) = each %MY_ENV ) {
> $ENV{ $k } = $v;
> }
> # ...
> open ...
>
> But Why !!!! why redeclaring ENV as local in a block do not work as expected
> w/ open !!! is it a bug, a feature or something I misunderstood ?
It would seem that this was a bug.. I have perl version 5.004_03
installed as our production version, but also have version 5.004_66 for
my own amusement. I ran the above script on both, and it worked
properly on 004_66.
One possibility is that %ENV is a magic data type, and that the
assignment of a new array didn't trigger the right perl opcodes. This is
speculation because I'm too lazy to look it up. When I take away the
'local' keyword, the environment is maintained correctly, so it probably
has to do with the 'local' flag that was attached to ENV. The copy back
was somehow triggered right before the exec'ing fork exited perl. I
altered the program to do a fork and exec( "sh", "-c", "set" ); and sure
enough, the environment was improperly restored.
Bare with the bug until the next official release, which will hopefully
be soon. I can't wait to 'officially' program in Threads..
------------------------------
Date: 23 Jul 1998 13:43:52 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: melspace@my-dejanews.com
Subject: Re: modifying a text file
Message-Id: <iukoif13.fsf@mailhost.panix.com>
melspace@my-dejanews.com writes:
> I am trying to figure out how to replace one line in a text file. I
> have read perlfaq5, but I am still puzzled. Can anyone suggest
> further readings or offer some help?
What part of perlfaq5 do you find unclear? Is it a specific line of
code? Some piece of terminology? Also, do you already know some
Perl? If not, then the FAQ will be of no use to you, and you should
start by reading _Learning Perl_.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: Thu, 23 Jul 1998 18:32:12 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: modifying a text file
Message-Id: <35b772c5.0@nnrp1.news.uk.psi.net>
Looking in the FAQ was a good start but what is it you are puzzled about.
Have you tried writing/running a test script? Do you need a more detailed
explanation of the process or are there specific bits concerning you?
Simon
melspace@my-dejanews.com wrote in message
<6p7os5$1ra$1@nnrp1.dejanews.com>...
>I am trying to figure out how to replace one line in a text file. I have
>read perlfaq5, but I am still puzzled. Can anyone suggest further readings
>or offer some help?
>
>Mel
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 23 Jul 1998 18:13:18 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: modifying a text file
Message-Id: <6p7ufu$d1l$3@marina.cinenet.net>
melspace@my-dejanews.com wrote:
: I am trying to figure out how to replace one line in a text file. I have
: read perlfaq5, but I am still puzzled. Can anyone suggest further readings
: or offer some help?
If you can tell us what about the perlfaq5 entry on this topic puzzles
you, we'd be more than happy to unpuzzle you. :)
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 23 Jul 1998 18:10:19 GMT
From: eoloughlin@my-dejanews.com
Subject: MsDev Automation with Perl
Message-Id: <6p7uab$8e4$1@nnrp1.dejanews.com>
Hi,
I'm trying to do an automated nightly build with DevStudio using perl & OLE.
I'm not very familiar with OLE and I'm having a problem setting the active
project (I've got multiple projects per workspace so I can have dependencies
in the workspace for daily use). I'm currently trying the following (adapted
from Dan Kegel's dswmake.pl - http://www.alumni.caltech.edu/~dank/msdev.htm):
my $app = CreateObject OLE "MSDev.Application";
$app->{'Visible'} = 1;
&printlog( "Opening $workspace_file\n");
$app->Documents->Open($workspace_file);
# Set the active project to $project_name
for ( $i = 1; $i <= $app->Projects->Count; $i++ )
{
my $curr_project = $app->Projects->Item($i);
if ( $curr_project->Name =~ /$project_name$/i )
{
$app->ActiveProject->{'Value'} = $curr_project;
}
}
I've tried a number of different variations on the above, e.g.
$app->ActiveProject($curr_project)
but to no avail. Win32::OLELastError returns a non-zero value (-2147352562)
if I call it from debug mode after trying to set the project which I don't
know how to interpret.
Any suggestions would be greatly appreciated - I've run out of ideas.
Thanks,
Ed O'Loughlin.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 23 Jul 1998 17:33:09 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Multiple Key Sort
Message-Id: <6p7s4l$sb7$1@pegasus.csx.cam.ac.uk>
F.Quednau <quednauf@nortel.co.uk> wrote:
>
>BTW
>Is it possible to explain how sort takes 2 elements of a list for
>comparison in relatively simple terms ?
What do you mean? Do you mean "What rule does sort use to decide
which pairs of elements to compare?" If so, read up about qsort()
in any textbook. Knuth Volume 3 "Sorting and Searching" will tell
you FMTYEWTK on the subject.
Mike Guy
------------------------------
Date: 23 Jul 1998 18:19:36 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Multiple Key Sort
Message-Id: <6p7uro$3ne$1@client3.news.psi.net>
Jeffrey J. Bachovchin (bachovch@dev.upenn.edu) wrote on MDCCLXXXVII
September MCMXCIII in <URL: news:35B72798.4FE9BCF6@dev.upenn.edu>:
++ Does anyone have a good algorithm for sorting data with multiple keys? I hav
++ what amounts to a matrix of data that needs to be sorted by a multiple number
++ columns and have tried everything but have not been able to come up with one
++ that works.
You haven't tried anything before you've studied the FAQ.
Abigail
--
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
for (??;(??)x??;??)
{??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'
------------------------------
Date: Thu, 23 Jul 1998 13:42:19 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: Multiple Key Sort
Message-Id: <35B775FB.636FCC38@sterlingdi.com>
> Does anyone have a good algorithm for sorting data with multiple keys? I have
> what amounts to a matrix of data that needs to be sorted by a multiple number of
> columns and have tried everything but have not been able to come up with one
> that works.
I am not completely sure how your data structure is set up.
A simplistic example of a sorting on multiple keys could be as follows:
Data Structure:
$obj = [ $key1, $key2, $key3, ..., $keyn, $data ] # possibly generated
through 'new'
@obj_list = ( $obj_1, ..., $obj_n )
# Sort based on keys.. When two keys are the same, compare the next
lowerer
# priority key.
@dest_list = sort {
return $_ if ( $_ = $a->[ $key1 ] <=> $b->[ $key1 ];
return $_ if ( $_ = $a->[ $key2 ] <=> $b->[ $key2 ];
...
return $a->[ $keyn ] <=> $b->[ $keyn ];
} @obj_list;
This could similarly be done using hash references instead of array
references.
If fields were strings instead of numbers, cmp would be used instead of
<=>.
If a key comparison was more complex, a function call could be used, as
long as it returned -1, 0, 1.
Maybe this algorithm could be optimized by declaring local variables to
avoid dereferencing...
------------------------------
Date: Thu, 23 Jul 1998 13:58:03 -0400
From: "Mark Stang" <markstang@ncgroup.com>
Subject: Newbie punctuation question
Message-Id: <6p7tk9$eus$1@usenet1.interramp.com>
I keep seeing references to punctuation in these postings. Is there a
definitive punctuation "dictionary" for new Perlers such as myself:
for example
BackWhack: \
Whack: /
Backtick: `
Shebang: #!
what others are there? or is there a source for all of these?
TIA
Mark
P.S. I've RTFFAQ
------------------------------
Date: Thu, 23 Jul 1998 19:04:10 +0100
From: Matt Pryor <matt@whiterabbit.co.uk>
To: groans@mailexcite.com
Subject: Re: Pattern Matching Snafus
Message-Id: <35B77B1A.D72FFDD@whiterabbit.co.uk>
You need to use the "s" modifier like this:
$html =~ s/<script.*\/script>//gis;
Which will count newlines in "."
Matt
groans@mailexcite.com wrote:
>
> Hi All, I posted this question to a similar newsgroup, but was directed back
> to this one because I had a better chance of getting an answer here. Here is
> the thing. I want to be able to read in a text file (specifically an html
> file) and be able to 1. find a keyword within that text 2. if that keyword
> exists in that text, it should be part of a javascript. And if that keyword
> exists, I want to be able to delete the Javascript from the page.
>
> My first idea was to do something like the following:
>
> #!/usr/local/bin/perl -w $file = 'rogue.html'; open(INFO, "$file"); @lines =
> <INFO>; foreach $line (@lines) { @fields =
> split(/[<]script.*[</]script/,$line); # or something like that print @fields;
> }
>
> This does not work though because ".*" stops matching once it gets to a
> newline character right? It will not match past the end of a string. But
> HTML text is multilined, and has many strings. So when there is javascript
> in it, it might look like this:
>
> <script LANGUAGE="JavaScript">
> script stuff here
> more script stuff here.
> </script>
>
> I need my perl script to start from the very first "<script.*" and delete or
> split things up until the last "</script>." I hope someone will have some
> advice for my on this. I have been looking everywhere for some answer to how
> to do this (yes I have three books on perl). Thanx in advance!
> ~Prime
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
--
Matt Pryor
http://www.whiterabbit.co.uk/cgi/cartoons.txt
------------------------------
Date: Thu, 23 Jul 1998 11:58:52 -0500
From: ferguson <ferguson@viz.tamu.edu>
Subject: Perl CGI image and text problem
Message-Id: <35B76BCC.856320CC@viz.tamu.edu>
Hello. I am trying to put text and images
onto a web page via Perl CGI. Can't seem
to get it right. Here's what I'm doing:
#!/usr/bin/perl -w
#./tryal: program to use the MRCM technique
use lib '/usr/lib/perl5';
use CGI qw(:standard);
$| = 1;
$giffile = "mrcm.0009.gif";
{
print "Content-type: image/gif\n";
print "\n";
binmode IMAGE;
open(IMAGE, "<$giffile") || die "Can't open $file: $!";
while (<IMAGE>)
{
print $_;
}
close(IMAGE);
print header, start_html("MRCM Warps Page"), h1("What's Going On?");
print p(" Data entered will be used for creating multiple copies of
an
... warps chosen, but which does not depend on the original image.");
}
This will give me an image, but not the text. If I put
the text before the image display routine, then I get text,
but the image doesn't show up, just the raw gif data.
I'm sure I'm missing something very simple here. I have
checked a large amount of resources, but am still frustrated.
Thanks in advance for any suggestions or advice.
John
------------------------------
Date: Thu, 23 Jul 1998 10:49:34 -0700
From: "Larry" <larryq@nospam.tuttle.com>
Subject: question about the @_ variable
Message-Id: <6p7t9d$rd0$1@nnrp2.crl.com>
Hi all,
I've got a little subroutine that does something like the following:
sub MySub
{
$tempvar=@_;
print length($tempvar);
}
the subroutine gets called like so:
$hello="hello world";
&MySub($hello);
What's strange is that the print $length($tempvar) statement above always
prints out a "1". So my question is how can I get the actual length of my
string out of that length() function? Just a basic question, but I've left
my Perl book at home!
------------------------------
Date: Thu, 23 Jul 1998 18:25:40 GMT
From: John Porter <jdporter@min.net>
Subject: Re: question about the @_ variable
Message-Id: <35B781B4.58C1@min.net>
Larry wrote:
>
> sub MySub {
> $tempvar = @_;
> print length($tempvar);
> }
>
> MySub( "hello world" );
>
> What's strange is that the print $length($tempvar) statement above always
> prints out a "1".
Not strange at all...
> So my question is how can I get the actual length of my
> string out of that length() function?
To do what you really meant to do:
sub MySub {
my( $tempvar ) = @_;
print length($tempvar);
}
It is likely that you want $tempvar to be lexically scoped (i.e.
private)
to the subroutine; hence the 'my'.
But more importantly, you want $tempvar to obtain the value of the
first element in @_. Just because you only passed one argument doesn't
mean that @_ starts acting like a scalar.
So you should assign @_ to a list -- even if the list only contains
one variable.
So why did you get those "strange" results?
What happens when you use an array variable in a scalar context
(as you did)? Why, you get the number of elements in the array.
If you had printed $tempvar, instead of length($tempvar), you
would have seen "1", which was the number of elements in @_.
Now, if you print length("1"), you get "1", of course.
hth,
--
John Porter
------------------------------
Date: Thu, 23 Jul 1998 11:30:10 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: question about the @_ variable
Message-Id: <MPG.1021210e9ff1490598973e@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy sent to Larry
<larryq@nospam.tuttle.com>.]
In article <6p7t9d$rd0$1@nnrp2.crl.com> on Thu, 23 Jul 1998 10:49:34 -
0700, Larry <larryq@nospam.tuttle.com> says...
...
> sub MySub
> {
> $tempvar=@_;
> print length($tempvar);
> }
>
> the subroutine gets called like so:
>
> $hello="hello world";
>
> &MySub($hello);
>
> What's strange is that the print $length($tempvar) statement above always
> prints out a "1". So my question is how can I get the actual length of my
> string out of that length() function? Just a basic question, but I've left
> my Perl book at home!
What is strange? You have assigned the number of arguments (the number
of elements in the *array* @_) to the scalar $tempvar. The number is 1,
and the length of '1' is 1. Try
$tempvar = $_[0];
or just
$tempvar = shift;
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 23 Jul 1998 12:46:46 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: References as strings
Message-Id: <35B768F5.B48E5CD1@sterlingdi.com>
> I am trying to store references as strings, and then later dereference
> them. THis far, I have not succeded. Perhaps someone could give me an
> advice.
>
> For example, if I do like this:
>
> $a = "string";
> $ref_to_a = \$a;
> $string_ref_to_a = "$ref_to_a";
>
> $string_ref_to_a upon being printed looks something like
> SCALAR(0x9f29c), but
> it can not be dereferenced. Is there a way to convert the "stringed"
> reference back into a hard reference, or some other way to get to the
> data in that location without using the real reference variable?
Just out of curiousity, why would you want/need to do so. Personally,
I'd think it was cool to be able to access real memory locations as in
C, but can't think of any real value in doing so in a scripting
language.
Hmm. Maybe you could write a C extension for it.
------------------------------
Date: Thu, 23 Jul 1998 13:18:27 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Regexp Help/Perl Help
Message-Id: <linberg-2307981318270001@projdirc.literacy.upenn.edu>
In article <6p7moc$v4c$1@nnrp1.dejanews.com>, chrisabraham@my-dejanews.com
wrote:
> Gurus:
(far from it, but anyway...)
<snip>
> It all seems like there is not
> enough stuff to figure it out...
> even for GREP, regular
> expression, and PERL!
If your data has consistent formatting, it's a pretty straightforward
regexp thing. There is *tons* of information about regexps all over the
place; I'd suggest Programming Perl, 2nd edition, which you either already
have or should be out the door right now to buy. There's also Mastering
Regular Expressions, both published by O'Reilly.
Good luck! And please don't post the same question twice under different
headers. We heard you the first time. :)
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: Thu, 23 Jul 1998 18:23:30 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: Regexp Help/Perl Help
Message-Id: <35b770b4.0@nnrp1.news.uk.psi.net>
>Any idea on how to do this?
>It all seems like there is not
>enough stuff to figure it out...
>even for GREP, regular
>expression, and PERL!
>
Blasphemer text manipulation is Perl's life!! ;-)
I'm just leaving so I don't have time now to knock up a proper script but
assuming the exhibit number always starts with a number ( if it doesn't you
could use the blank line as your seporator to search for ) followed by a
list of names ( I assume noones name starts with a number! ) then
conceptually its easy ( not wishing to sound patronising ). All you need to
do is loop through the file look for a line that starts with a number and
untill you get another line starting with a number store all the following
lines in a way that refers to the exhibit number. You will have a problem if
you don't know whether the entry is firstname, lastname or
lastname,firstname as no regexp known to man could differentiate between the
two and so you will just have to store them as is or get them in a known
format..
Something roughly like:
my %data;
my $current_exhibit;
open DATA, "somefile" or die "Unable to open file:$!";
while( <DATA> ) {
if( /^\d/ ) {
$current_exhibit = $_;
#Start an array for the names with the exhibit no. as key
@{$data{$current_exhibit}} = ();
} else {
push @{$data{$current_exhibit}}, $_;
}
}
Then just get the data from %data and sort it as required, I'm sure the the
above is not 100% perfect but it should give you enough to get started on.
Have Fun
Simon
chrisabraham@my-dejanews.com wrote in message
<6p7moc$v4c$1@nnrp1.dejanews.com>...
>Gurus:
>
>Any idea on how to do this?
>It all seems like there is not
>enough stuff to figure it out...
>even for GREP, regular
>expression, and PERL!
>
>Any help would be pennies from heaven!
>
>Cheers,
>
>Chris Abraham
>
>--
>chris.abraham<cja@SPAMdds.nl><http://urban.net/chris>
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 23 Jul 1998 13:08:43 -0700
From: "J. Pratt" <jpratt@command-central.nmsd.k12.nm.us>
To: Tad McClellan <tadmc@flash.net>
Subject: Re: result pending code..?
Message-Id: <35B7984B.123CDC27@command-central.nmsd.k12.nm.us>
Excellent response and idea.. This has me on the right track, it seems.
Thanks much, Tad.
- J. Pratt
Tad McClellan wrote:
> I'd write a mail filter.
>
> When you _receive_ the message, just 'reply' to it.
>
> Have a mail filter that will go delete the file when it gets the > reply.
------------------------------
Date: Thu, 23 Jul 1998 13:19:28 -0400
From: Tony Labbiento <tonylabb@infonline.net>
Subject: Re: sort email list
Message-Id: <35B770A0.DF4076F5@infonline.net>
ken@co.greenwood.sc.us wrote:
>
> I have a script to read my email file, sort by last name and display an html
> page. It works fine except that if I have more than one person with the same
> last name, then only one of the names is printed (presumably the one at the
> top of the alphabetically order). Below is my script if someone could give
> me a tip. Thanks.
>
> Ken
>
> Script:
>
> #!/usr/bin/perl
>
> $filename="/public/email2.txt";
> $bgimage = "/backgrnd.jpg";
>
> print "Content-type: text/html\n\n"; print <<HTMLHead; <html><body
> background=\"$bgimage\"><center><h2>E-Mail Listing</h2></center> HTMLHead ;
> print "<center><h3>Includes County, City and Solicitor
> Offices</h3></center>"; print "<center>Alphabetical by last name</center>";
> print "<i>Last revised: June 23, 1998</i>"; print "<hr>"; print "<ul>";
>
> open(EMAIL,$filename) or die "Could not open the email file : $!";
> while (<EMAIL>) { ($id,$first,$last) = split(/\s+/);
> #print "$last, $first\n e-mail:$id\@co.greenwood.sc.us\n";
>
> # ** Build the hash of arrays. Key is the last name.
> $email_list{$last} = [($id, $first)];
----------------------^^^^^
Here is your problem. Hashes must have unique keys. When a key is
duplicated ($last) the value gets overwritten.
>
> }
>
> # Sort the hash on last name.
> foreach $key (sort keys %email_list){
>
> # Access the array associated with the key.
> ($id, $first) = @{$email_list{$key}};
> #print "$key, $first"
> print "<a href=mailto:";
> print "$id";
> print "@";
> print "co.greenwood.sc.us>";
> print "$key, $first<br>";
> #print "The last name is : $key\t";
> #print "The first name is : $first\t";
> #print "The email id is : $id\n";
> }
> close(EMAIL) or die "Could not close the email file : $!";
> print "</ul>";
> print "<hr>";
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
--
****************************************
* Tony Labbiento *
* Infinity Online, Inc. *
****************************************
------------------------------
Date: Thu, 23 Jul 1998 18:28:50 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: sort email list
Message-Id: <35b771fb.0@nnrp1.news.uk.psi.net>
Your problem is you are using the last name as the hash key so you will only
ever get one entry for any given last name and that one will be the last one
you read in as they will repeatedly overwrite the old one. What you need is
to have a slight rething and find either a different _unique_ key to use or
reorganise how you are storing your data.
Simon
ken@co.greenwood.sc.us wrote in message <6p7njg$da$1@nnrp1.dejanews.com>...
>I have a script to read my email file, sort by last name and display an
html
>page. It works fine except that if I have more than one person with the
same
>last name, then only one of the names is printed (presumably the one at the
>top of the alphabetically order). Below is my script if someone could give
>me a tip. Thanks.
>
>Ken
>
>Script: <snipped>
------------------------------
Date: Thu, 23 Jul 1998 14:30:01 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: STUMPED!!! (perl trivia)
Message-Id: <35B78128.331D9070@sterlingdi.com>
> > I have a variable $x containing a pack()ed, nil-padded string (to be
> > precise, it was produced via pack('a64', "foo"), but, in general, the
> > unpadded length is unknown); I want to produce a variable $y
> > containing the unpadded string. To my chagrin, I haven't managed to
> > come up with anything better than:
> >
> > $y = join('', map chr, grep($_ > 0 , unpack 'c*', $x))
> >
> > Since I've "solved" the problem, however inelegantly, I guess this
> > question reduces to one of perl trivia: how to do this more elegantly?
> > I'm sure there's a simple, direct way of doing this, but hellifiknow
> > what it is. Any ideas?
> >
> > K.
> >
> >
> >
>
> How about:
>
> ($y) = $x =~ /([^\0]*)/;
>
> or: (assumes padding exists)
>
> $y = substr $x,0,index ($x,"\0");
As a slight optimization/generalization
$y = ( ( $_ = index($x,"\0") ) > 0 )?
substr( $x, 0, $_ ) :
$x;
or
($y) = $x =~ /(^[^\0]*)/;
------------------------------
Date: Thu, 23 Jul 1998 20:03:28 +0200
From: Francesc Guasch <frankie@etsetb.upc.es>
To: saadiqr@princeton.edu
Subject: Re: su function
Message-Id: <35B77AF0.3B6E6467@etsetb.upc.es>
saadiqr@princeton.edu wrote:
>
> Is there a function that would effectively change the 'user' which the program
> is running as? My little "Learning Perl" copy hasn't been that helpful. A
> sort of...
> su $id pw$;
There are perl vars that can set the uid.
perldoc perlvar and search about uid, you'll find these
and more info and examples.
$< The real uid of this process. (Mnemonic: it's the
uid you came FROM, if you're running setuid.)
$> The effective uid of this process.
if you do man perl, you'll find a list of many docs that
came free with your perl distribution. enjoy.
--
mailto:frankie@etsetb.upc.es http://www.etsetb.upc.es/~frankie
^-^.-----,
o o _ ) Linux, Windows 95, and Windows NT
Y (_, (__(Ssss (also known as the Good, the Bad, and the Ugly)
------------------------------
Date: 23 Jul 1998 17:05:45 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: what is the difference between "tie" & "dbmopen"?
Message-Id: <6p7qh9$run$1@pegasus.csx.cam.ac.uk>
Susan Cheung <sschng6@ie.cuhk.edu.hk> wrote:
>As title,
Err.. one has three letters and the other seven?
Nope. That's probably not the answer you want.
tie is documented in perldoc perltie
dbmopen is documented in perldoc -f dbmopen
What part of the documentation didn't you understand? Or what points
weren't covered in the documentation?
Mike Guy
------------------------------
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 3236
**************************************