[12836] in Perl-Users-Digest
Perl-Users Digest, Issue: 246 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 24 20:07:20 1999
Date: Sat, 24 Jul 1999 17:05:09 -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 Sat, 24 Jul 1999 Volume: 9 Number: 246
Today's topics:
Re: Amateur (Larry Rosler)
Re: Best Perl book? <escobar@oxy.edu>
Re: Extracting plain text from email <cw@dwc.ch>
Re: Finding duplicate elements in an array? (Larry Rosler)
Re: Geekspeak Programming Contest (Larry Rosler)
Re: Geekspeak Programming Contest (Hakan Hjelmstrom)
its 1.30am and time to ask for help - eval (Eric Smith)
Re: John F. Kennedy, Jr <cassell@mail.cor.epa.gov>
Re: John F. Kennedy, Jr <qwerty@post.utfors.se>
Re: John F. Kennedy, Jr (Larry Rosler)
Re: John F. Kennedy, Jr <cw@dwc.ch>
Re: John F. Kennedy, Jr (Eric Bohlman)
Odd Behavior <llornkcor@llornkcor.com>
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Randal L. Schwartz)
Re: output of print map ( { unless (/^#/) {} } ("#") ); (Larry Rosler)
Re: Perl 4 Source Code or Binaries (Anno Siegel)
Re: Perl Cookbook 2nd Ed. ? <mike@crusaders.no>
perl-DBI-mySQL-html <klaus.oberecker@gmx.at>
Re: perl-DBI-mySQL-html <cw@dwc.ch>
Re: perl-DBI-mySQL-html (Abigail)
Re: perl-DBI-mysql (Eric Bohlman)
Re: printing array and `\n' - huh? (Abigail)
Re: printing array and `\n' - huh? (Larry Rosler)
Re: Scalar to Array Question (Abigail)
Re: Scalar to Array Question <aperrin@mcmahon.qal.berkeley.edu>
Re: Scalar to Array Question (Abigail)
Re: some really wierd behavior with POST? <qwerty@post.utfors.se>
special problem <debot@xs4all.nl>
Re: special problem <tchrist@mox.perl.com>
Re: split([tabulator],$line ); (Larry Rosler)
Re: Submitting Photos <Floyd@NewWebSite.com>
Re: Submitting Photos (Abigail)
Re: Using FAQ in ActiveStates Perl (Abigail)
Re: Variables in Regx? (Larry Rosler)
Re: Variables in Regx? (Argouarch)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 24 Jul 1999 16:19:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Amateur
Message-Id: <MPG.1203e9ba234b6bac989d3c@nntp.hpl.hp.com>
In article <7nd9vq$p5c$1@216.39.141.200> on 24 Jul 1999 21:08:10 GMT,
Neko <tgy@chocobo.org> says...
...
> Perhaps perl optimizes this to read only two lines and seek to the end of the
> file (I do not know this to be true):
>
> ($wordline, $locks) = <CONFI>;
How could it? Some absolute dumbhead might want to know the total
number of lines in the file.
$count = ($wordline, $locks) = <CONFI>;
[This is provoked by another current thread about transferring the count
from the far right through a list assignment to a scalar.]
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Jul 1999 15:16:56 PDT
From: "Julio R. Escobar" <escobar@oxy.edu>
Subject: Re: Best Perl book?
Message-Id: <7nde0o$3g9@chronicle.concentric.net>
I use the book titled Teach Yourself PERL for Windows NT in 21 days. Even
though the title may lead you to think that the book is corrupted with
Windoze, it is not. Most of the book is dedicated to PERL itself, and the
last chapter or two talk about PERL for Win32.
The good thing about this book is that it pretty much takes you by the hand.
It does not make assumptions about you know or don't know, like the O'Reilly
books. It is very thorough in the way that it
a.. presents concepts
b.. gives examples and exercises
c.. analyzes output results or lines of examples
d.. makes notes of things to watch out for
e.. takes one lesson at a time
It may take you longer than 21 days to cover the entire book. It would take
you 21 days to cover the whole book, given that all you do during that time
is read and practice the exercises in it. However, the strength of the book
is the fact that it is structured to be covered in 21 days. It is
structured in morning and afternoon lessons, and gives you a sense of
accomplishment as you go along. It is up to you how many lessons you want
to cover.
The O'Reilly books are for more experienced programmers, and it makes
assumptions about what you know and don't know.
Julio
Unigni wrote in message ...
>I have a little programming experience, and want to start learning Perl,
>probably for CGI use on the Web... Can anybody suggest what would be the
>best book(s) to get?
>--
>Philip Taylor
>philip @ zaynar . demon . co . uk
>http://www.ultrastore.com -- "The Shopping Experience of Tomorrow - NOW!"
> (an example of what can be done with *loads* of JavaScript and
cookies!)
------------------------------
Date: Sun, 25 Jul 1999 01:40:14 +0200
From: Christoph Wernli <cw@dwc.ch>
Subject: Re: Extracting plain text from email
Message-Id: <379A4ED9.708CBD52@dwc.ch>
Tom Christiansen wrote:
>
> :How can you get the plain text version of an email out of all the headers
> :and if it been sent in html format loose all the formating below the main
> :body of the message.
>
> What is "loose"? Did you mean to write "lose"? Why didn't you?
> After reading it a dozen times in one day, it gets to you.
>
> Some of us autobounce all HTML or binary mailings sight unseen.
> It's better that way. If more people would do that, there'd be less
> crap in our mailboxes.
If you don't feel like saving the world right now, check out
http://theory.uwinnipeg.ca/scripts/CPAN/authors/id/ERYQ/MIME-Lite-1.135.tar.gz,
http://theory.uwinnipeg.ca/scripts/CPAN/authors/id/GAAS/HTML-Tree-0.51.tar.gz and http://theory.uwinnipeg.ca/scripts/CPAN/authors/id/GBARR/MailTools-1.13.tar.gz
-w
------------------------------
Date: Sat, 24 Jul 1999 15:36:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Finding duplicate elements in an array?
Message-Id: <MPG.1203dfe0a2fd9c2d989d38@nntp.hpl.hp.com>
In article <379A1684.16CE3D74@netdoor.com> on Sat, 24 Jul 1999 14:39:48
-0500, Kevin Kinnell <kejoki@netdoor.com> says...
> Pfash1 wrote:
> [snip]
> > I want to march thru this array and compare each element to
> > every other one to find out if there are any duplicates ...
> [snip]
> > (ps. I eventually want to eliminate the duplicates so there is
> > only one of each.)
<SNIP> of quoted sig, which violates netiquette.
> I'll try this one, and if I violate the group ettique... ettequ...
> rules of propriety I will be suitably ashamed and do better next
> time.
Some would consider posting a solution that is worse than the solutions
in the FAQ to be a netiquette violation.
> [On the other hand, I'll bet this is the wrong place to post this
> question; if so you'll be enlightened and if not I will be. 'B)> ]
It is the right place, but it shouldn't have been posted in any case
because it is a FAQ. So you are both wrong.
> Something like
>
> #
> foreach $elem (sort @array) {
> ($prev eq $elem) && next;
> $prev = $elem;
> push @uniqary, $elem;
> }
> #
>
> should work, with whatever scoping changes you need to
> make for the situation..
It is O(N * logN), whereas the solutions in the FAQ are O(N). (It also
fails to initialize $prev, which causes a '-w' warning.) See the FAQ,
solution (a), which deals with an already sorted array. The other
solutions don't, and don't sort it.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 24 Jul 1999 15:25:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Geekspeak Programming Contest
Message-Id: <MPG.1203dd208ee7f856989d37@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <379a3095@cs.colorado.edu> on 24 Jul 1999 15:31:01 -0700, Tom
Christiansen <tchrist@mox.perl.com> says...
> This is for inspiration.
>
> --tom
>
> #!/usr/bin/perl
> #
> # geekspeak correspondence lister
> # tchrist@perl.com
...
I am inspired to post code without '-w' and 'use strict;' in the future.
:-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 24 Jul 1999 22:45:15 GMT
From: hawk@algonet.se (Hakan Hjelmstrom)
Subject: Re: Geekspeak Programming Contest
Message-Id: <379a4197.2502087@news.algonet.se>
On 22 Jul 1999 13:13:01 -0700, Tom Christiansen:
> Your mission, should you choose to accept it, is to write a translator
> program than converts from one lingo to the other, or vice versa.
> The program should work for translating between other domains as
> well, such as East Coast vs West Coast jargon, programmer vs
> manager, etc.
You mean something like http://www.rinkworks.com/dialect/
Håkan Hjelmström
hawk@algonet.se
------------------------------
Date: 24 Jul 1999 23:31:25 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: its 1.30am and time to ask for help - eval
Message-Id: <slrn7pkj6t.8hn.eric@plum.fruitcom.com>
Hi
I am not winning trying to get eval to do what I want.
Here is my effort
#!/usr/bin/perl -w
$one="print";
$two="'Hello World'";
print "@ARGV \n";
print "print \"";
for $i (0..$#ARGV){
if ($i == $#ARGV) {$array .= "/$ARGV[$i]/\"\;"} else
{$array .= "/$ARGV[$i]/ and "}
}
print $array;
eval $array;
eval $one . $two;
Ok, the hello world part works.
But the eval of the $array dont. I think it is more politically correct to
name the for block and then to the eval on the named block but that did not
work for me.
This is just a prototype and must print the args inbetween slashes.
Thanx for your suggestions.
--
Eric Smith
<eric@fruitcom.com>
www.fruitcom.com
Tel. 021 423 6111
------------------------------
Date: Sat, 24 Jul 1999 15:11:09 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: John F. Kennedy, Jr
Message-Id: <379A39FD.CF7043C2@mail.cor.epa.gov>
hakn@ecn.ab.ca wrote:
>
> I'll never understand Americans. John F. Kennedy wanted to be buried at
> sea. He arranged his funeral that way and they pull him out, dry him off,
> burn him and toss his ashes back in the same spot.
And you wanted to do it in Perl?
HAND,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sat, 24 Jul 1999 00:54:33 +0200
From: "Dr. Who" <qwerty@post.utfors.se>
Subject: Re: John F. Kennedy, Jr
Message-Id: <3798F2A9.118C3BD5@post.utfors.se>
Andrei Chikatilo was just a lame shadow of his father
hakn@ecn.ab.ca wrote:
> I'll never understand Americans. John F. Kennedy wanted to be buried at
> sea. He arranged his funeral that way and they pull him out, dry him off,
> burn him and toss his ashes back in the same spot.
>
> --
> Harold Knopke
------------------------------
Date: Sat, 24 Jul 1999 16:13:03 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: John F. Kennedy, Jr
Message-Id: <MPG.1203e85327c98fd9989d3b@nntp.hpl.hp.com>
[Posted and a dis-courtesy copy sent.]
In article <379a1532.0@ecn.ab.ca> on 24 Jul 99 19:34:10 GMT,
hakn@ecn.ab.ca <hakn@ecn.ab.ca> says...
> I'll never understand Americans. John F. Kennedy wanted to be buried at
> sea. He arranged his funeral that way and they pull him out, dry him off,
> burn him and toss his ashes back in the same spot.
And your Perl question is?
This is not a soapbox for random opinions.
There is no particularly polite way to tell you to shove it.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 25 Jul 1999 01:24:32 +0200
From: Christoph Wernli <cw@dwc.ch>
Subject: Re: John F. Kennedy, Jr
Message-Id: <379A4B2C.A1DD0510@dwc.ch>
David Cassell wrote:
>
> hakn@ecn.ab.ca wrote:
> >
> > I'll never understand Americans. John F. Kennedy wanted to be buried at
> > sea. He arranged his funeral that way and they pull him out, dry him off,
> > burn him and toss his ashes back in the same spot.
>
> And you wanted to do it in Perl?
I'll never understand Americans. As soon as they have something to cheer about, they want
to rewrite it.
-w
------------------------------
Date: 24 Jul 1999 23:31:42 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: John F. Kennedy, Jr
Message-Id: <7ndicu$e53@dfw-ixnews13.ix.netcom.com>
hakn@ecn.ab.ca wrote:
: I'll never understand Americans. John F. Kennedy wanted to be buried at
: sea. He arranged his funeral that way and they pull him out, dry him off,
: burn him and toss his ashes back in the same spot.
There's an explanation of this in the POD for Customs::Funeral, available
from your nearest CPAN site.
------------------------------
Date: 24 Jul 1999 17:38:38 -0600
From: llornkcor <llornkcor@llornkcor.com>
Subject: Odd Behavior
Message-Id: <btd18vpd.fsf@wind.localdomain>
Why does this line
print "<a href=\"$file\">$file</a><BR>";
give an output of
<a href="myfile
">myfile
</a><BR>
Is there anyway to get this to output without the magical new lines?
--
llornkcor rocknroll
SpiritShip MultiMedia Recording Studio
www.llornkcor.com
(0 0)
+=======================----oOO--(_)--OOo----=========================+
__ _
/ / (_)__ __ ____ __
/ /__/ / _ \/ // /\ \/ /
/____/_/_//_/\_,_/ /_/\_\
The choice of a GNU generation...
------------------------------
Date: 24 Jul 1999 16:17:43 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <m1aeslk57s.fsf@halfdome.holdit.com>
>>>>> "Michael" == Michael Wang <mwang@tech.cicg.ml.com> writes:
Michael> unless (/^#/) {} is legal expression just to demonstrate the problem.
"unless (/^#/) {}" is not an expression at all. It's a statement.
Statements don't have "values". The map operator takes the value
of the last expression evaluated, wherever it is, in a list context
and uses that value (or values) to build the output list.
If the match succeeds, the unless doesn't execute the body, and you
get a 1. If the match fails, we get whatever was in the body, here
nothing, so no elements get contributed.
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: Sat, 24 Jul 1999 16:57:29 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: output of print map ( { unless (/^#/) {} } ("#") );
Message-Id: <MPG.1203f2c4c4a32d989d3e@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <7nd1ou$ge2$1@news.ml.com> on 24 Jul 1999 18:47:58 GMT,
Michael Wang <mwang@tech.cicg.ml.com> says...
...
> ... What I want to do is to create a hash from
> a file of two columns, but it may have empty lines /^\s*$/, comment lines
> /^#/, or comment s:#.*::. So I came up with the following:
>
> %assoc= map({
> if (/^#/ || /^\s*$/) {
> ;
> } else {
> s:#.*::;
> split;
> }
> } <README>);
>
> What my question/problems are (1) I can not safely "safely" use if/unless
> inside the the map block, since as you said, the return value of
> if/unless is not defined. And I do not know how can I do without using
> if/unless.
All UNTESTED.
Use the conditional operator ?: :
%assoc = map {
/^#/ || /^\s*$/ ? () : do { s:#.*::; split; }
} <README>;
Use the 'grep' function:
%assoc = map { s:#.*::; split; } grep !(/^#/ || /^\s*$/), <README>;
Use a loop:
while (<README>) {
next if /^#/ || /^\s*$/;
s:#.*::;
my ($key, $val) = split;
$assoc{$key} = $val;
}
> (2) I can not control what get into return from map to assoc,
> for example, /^#/ || /^\s*$/ may return something, s:#.*:: may return
> something. In shell, what I want to return, I "echo", what I don't want,
> I "> /dev/null".
Return an explicit empty list (), but as you see above, there are better
ways.
%assoc= map({
if (/^#/ || /^\s*$/) {
();
} else {
s:#.*::;
split;
}
} <README>);
> (3) I can not use "last", "next" in map block. For example,
> I may want to get one pair from the file README, as soon as I found the
> pair, I jump out the loop.
while (<README>) {
next if /^#/ || /^\s*$/;
s:#.*::;
%assoc = split;
last;
}
> Any advice to do what I wanted to do above is greatly appreciated.
The 'split-and-assign-to-hash' solutions all assume that 'split' returns
exactly two values. This is not conservative coding. You could/should
use
split / /, $_, 2
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Jul 1999 23:30:17 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl 4 Source Code or Binaries
Message-Id: <7ndia9$44c$1@lublin.zrz.tu-berlin.de>
Dr. Who <@no.no> wrote in comp.lang.perl.misc:
>hmm ..in sweden Anno is a female name ..
...and in Latin it's "in the year". Thanks for playing.
Anno
------------------------------
Date: Sun, 25 Jul 1999 00:07:26 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: Perl Cookbook 2nd Ed. ?
Message-Id: <JOqm3.463$2s2.3086@news1.online.no>
TK Soh <r28629@email.sps.mot.com> wrote in message
news:379A01BC.16772AFC@email.sps.mot.com...
> I though I heard someone said the 2nd Ed. of Perl Cookbook is one its
> way, is it real? Anybody?
Why would a second edition of the cookbook be necessary? A vol. 2 would be
nice though..
--
Trond Michelsen
------------------------------
Date: Sat, 24 Jul 1999 22:27:28 GMT
From: Klaus Oberecker <klaus.oberecker@gmx.at>
Subject: perl-DBI-mySQL-html
Message-Id: <379A3ECB.751453C7@gmx.at>
I´ve a questione conerning perl/DBI/html:
* I´ve stored pictures (jpg and gif) in a mySQL-DB
* I can display each picture (with perl/DBI) in a browser by setting
Content-type of the page to type "image"
My questione:
How can I load more than one picture in a html-page???? - e.g. a series
of pictures into a html-table???? - Where can I find some examples???
klaus oberecker
------------------------------
Date: Sun, 25 Jul 1999 01:08:09 +0200
From: Christoph Wernli <cw@dwc.ch>
To: Klaus Oberecker <klaus.oberecker@gmx.at>
Subject: Re: perl-DBI-mySQL-html
Message-Id: <379A4756.BBF331FB@dwc.ch>
[mailed & posted]
Klaus Oberecker wrote:
>
> I´ve a questione conerning perl/DBI/html:
>
> * I´ve stored pictures (jpg and gif) in a mySQL-DB
> * I can display each picture (with perl/DBI) in a browser by setting
> Content-type of the page to type "image"
>
> My questione:
>
> How can I load more than one picture in a html-page???? - e.g. a series
> of pictures into a html-table????
>
> Where can I find some examples???
comp.infosystems.www.authoring.*
-w
------------------------------
Date: 24 Jul 1999 18:56:40 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: perl-DBI-mySQL-html
Message-Id: <slrn7pkkkh.41s.abigail@alexandra.delanet.com>
Klaus Oberecker (klaus.oberecker@gmx.at) wrote on MMCLIII September
MCMXCIII in <URL:news:379A3ECB.751453C7@gmx.at>:
##
## How can I load more than one picture in a html-page???? - e.g. a series
## of pictures into a html-table???? - Where can I find some examples???
That's an html question. Go ask in an html group.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== 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: 24 Jul 1999 23:19:31 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: perl-DBI-mysql
Message-Id: <7ndhm3$e53@dfw-ixnews13.ix.netcom.com>
Klaus Oberecker (klaus.oberecker@gmx.at) wrote:
: I´m trying to load images with a perl/dbi script into a mySQL-db. - I´ve
: wrote a small test-skript:
:
: ----
: test.pl
: ----
: use DBI;
: $dbh=DBI->connect("DBI:mysql:mydb",'xxxxxx','yyyyyy');
:
: local (*FH);
: ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)=
: stat('xxxx.jpg');
: open FH, 'xxxx.jpg';
: $retval = read FH, $img_str, $size;
: $picture=\$img_str;
$picture is a *reference* to a scalar holding the binary image data.
:
: $my_sql_statement="INSERT INTO tablename (uid,vorname, nachname,
: bildtyp, pict) VALUES (0,'Prename','Surename',0,$picture)";
Interpolating a reference like $picture into a double-quoted string
stringifies it. You have *not* inserted the binary image data into your
statement.
: $sth = $dbh->prepare($my_sql_statement);
: $rv=$sth->execute($bild);
: $dbh->disconnect;
: ----
:
: ... but I always get this error-message:
:
: DBD::mysql::st execute failed: You have an error in your SQL syntax near
: '(0x812542c))' at line 1 at test.pl line
: 12.
That's what a stringified reference looks like.
------------------------------
Date: 24 Jul 1999 17:07:25 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: printing array and `\n' - huh?
Message-Id: <slrn7pke7m.3sr.abigail@alexandra.delanet.com>
Eric Smith (eric@fruitcom.com) wrote on MMCLIII September MCMXCIII in
<URL:news:slrn7pk88t.8hn.eric@plum.fruitcom.com>:
// Hi
//
// I go
//
// @wow=qw(bumble bee);
//
// and any of these ...
// print "@wow \n";
// print @wow;
// print "@wow" . "\n";
// gives ..
// `bumble bee'
//
// But when I go
// print @wow . "\n";
// I get ...
// `2'
//
// Yeah the number of elements in the array or the array in a scalar context.
// How so?
Because you are using the array in scalar context.
Abigail
--
perl -wle '(1 x $_) !~ /^(11+)\1+$/ && print while ++ $_'
-----------== 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: Sat, 24 Jul 1999 16:23:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: printing array and `\n' - huh?
Message-Id: <MPG.1203eab84845fa99989d3d@nntp.hpl.hp.com>
In article <Pine.GSO.4.10.9907241704430.6977-100000@crusoe.crusoe.net>
on Sat, 24 Jul 1999 17:07:06 -0400, japhy <jeffp@crusoe.net> says...
> On 24 Jul 1999, Eric Smith wrote:
> > print "@wow \n";
> > print @wow;
> > print "@wow" . "\n";
> > `bumble bee'
...
> > print @wow . "\n";
> > `2'
>
> Now that concatenation operator... THAT treats its operands in scalar
> context. So @wow in scalar context is the number of elements in it.
And the simplest solution is to replace the period by a comma.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Jul 1999 17:10:30 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Scalar to Array Question
Message-Id: <slrn7pkedf.3sr.abigail@alexandra.delanet.com>
Jody Fedor (JFedor@datacom-css.com) wrote on MMCLIII September MCMXCIII
in <URL:news:7nd9vl$qd4$1@plonk.apk.net>:
!! Don't know where to look for information:
!!
!! I have a Scalar variable called $items.
!!
!! $items contains:
!!
!! 1090:2.5" 1.2GB Hard Drive:1:129.00 \n <--- Carriage return or newline
!! 1250:blah blah:5:5.50 \n
!!
!! I'd like to turn this into an array so I can process the file using foreach.
Turn into an array... There are gazillions of ways to make an array.
Some ways:
@array = ($item);
@array = split // => $item;
@array = $item =~ /(\S+)/gs;
What exactly do you want?
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
-----------== 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: Sat, 24 Jul 1999 16:17:04 -0700
From: Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: Scalar to Array Question
Message-Id: <379A4970.9EB102F@mcmahon.qal.berkeley.edu>
Jody Fedor wrote:
> my @itema = ($items =~ /\n/g);
huh? try:my @itema = split(/\n\, $items);
ap
--
-------------------------------------------------------------
Andrew Perrin - NT/Unix/Access Consulting - aperrin@mcmahon.qal.berkeley.edu
I'M LOOKING FOR ANOTHER EXPERIENCED ACCESS
DEVELOPER - CONTACT ME IF INTERESTED.
http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------
------------------------------
Date: 24 Jul 1999 19:00:05 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Scalar to Array Question
Message-Id: <slrn7pkkqu.41s.abigail@alexandra.delanet.com>
Jody Fedor (JFedor@datacom-css.com) wrote on MMCLIII September MCMXCIII
in <URL:news:7ndcja$rrq$1@plonk.apk.net>:
$$
$$ my @itema = ($items =~ /\n/g);
$$
$$ foreach $itema (@itema) {
$$ ($item, $desc, $qty, $price) = split /:/, $itema, 4;
$$ print "$item, $desc, $qty, $price<br>";
$$ }
$$
$$ This does not work, I only get a row of ,,, as the output, funny though, I
$$ get the exact number of rows as there are items in the scalar.
Well, your @itema is an array containing nothing but strings equal to "\n".
So, each split gives 4 undefined values. Hence, the print only prints
commas, and the <br>.
Perhaps you want to use: @itema = split /\n/ => $item; ?
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
-----------== 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: Sat, 24 Jul 1999 00:48:58 +0200
From: "Dr. Who" <qwerty@post.utfors.se>
Subject: Re: some really wierd behavior with POST?
Message-Id: <3798F15A.AAF2795@post.utfors.se>
someone 'll have to rewrite the documentation :)
.. ok ..really I haven't looked that hard
Andrew J Perrin wrote:
> Dr. Who wrote:
>
> > The following code is just a fragment of a guestbook .. but it shows a
> > problem with post?
> > or perhaps a lame thing I have done myself?
> > ...
> > Any suggestions?
> >
>
> Sure...use CGI;
>
> --
> -------------------------------------------------------------
> Andrew Perrin - NT/Unix/Access Consulting -
> aperrin@mcmahon.qal.berkeley.edu
> I'M LOOKING FOR ANOTHER EXPERIENCED ACCESS
> DEVELOPER - CONTACT ME IF INTERESTED.
> http://www.geocities.com/SiliconValley/Grid/7544/
> -------------------------------------------------------------
------------------------------
Date: Sun, 25 Jul 1999 00:15:49 +0200
From: Frank de Bot <debot@xs4all.nl>
Subject: special problem
Message-Id: <379A3B15.AD6144F5@xs4all.nl>
I want to do something weird ( I think ).
I have a string which is called array:
$string = "array";
Now I want to create an array with that variable.
@array = ""; # To put something in it is for later
if I have a string whit the value "mp3" I want to create a array @mp3
Is this possible?
--
Penpal International , Searchy.net
http://www.debot.nl/ppi , http://www.searchy.net/
ppi@debot.nl , support@searchy.net
------------------------------
Date: 24 Jul 1999 17:03:32 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: special problem
Message-Id: <379a4644@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
Frank de Bot <debot@xs4all.nl> writes:
:I want to do something weird ( I think ).
:I have a string which is called array:
:
:$string = "array";
:
:Now I want to create an array with that variable.
:
:@array = ""; # To put something in it is for later
:
:if I have a string whit the value "mp3" I want to create a array @mp3
:
:Is this possible?
=head2 How can I use a variable as a variable name?
Beginners often think they want to have a variable contain the name
of a variable.
$fred = 23;
$varname = "fred";
++$$varname; # $fred now 24
This works I<sometimes>, but it is a very bad idea for two reasons.
The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether. Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.
Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.
The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes. By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash. The solution is to
use your own hash or a real reference instead.
$fred = 23;
$varname = "fred";
$USER_VARS{$varname}++; # not $$varname++
There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables. This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one. Instead of
reading a string and expanding it to the actual contents of your program's
own variables:
$str = 'this has a $fred and $barney in it';
$str =~ s/(\$\w+)/$1/eeg; # need double eval
Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:
$str =~ s/\$(\w+)/$USER_VARS{$1}/g; # no /e here at all
That's faster, cleaner, and safer than the previous approach. Of course,
you don't need to use a dollar sign. You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.
$str = 'this has a %fred% and %barney% in it';
$str =~ s/%(\w+)%/$USER_VARS{$1}/g; # no /e here at all
Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes. For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.
$name = "fred";
$$name{WIFE} = "wilma"; # set %fred
$name = "barney";
$$name{WIFE} = "betty"; # set %barney
This is still a symbolic reference, and is still saddled with the
problems enumerated above. It would be far better to write:
$folks{"fred"}{WIFE} = "wilma";
$folks{"barney"}{WIFE} = "betty";
And just use a multilevel hash to start with.
The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table. This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.
In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table. For example:
@colors = qw(red blue green yellow orange purple violet);
for my $name (@colors) {
no strict 'refs'; # renege for the block
*$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
}
All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.
So, sometimes you might want to use symbolic references to directly
manipulate the symbol table. This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
--
Perle, plesaunte to prynces paye/ To clanly clos in golde so clere,
Oute of oryent, I hardyly saye/ Ne proued I neuer her precios pere.
------------------------------
Date: Sat, 24 Jul 1999 15:46:44 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: split([tabulator],$line );
Message-Id: <MPG.1203e22a9f96551f989d39@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <3799F03F.E2E9B491@cnm.de> on Sat, 24 Jul 1999 18:56:31
+0200, Marten Lehmann <lehmann@cnm.de> says...
> how can I split a line by the sign of the tabulator?
One cannot answer this without knowing what a tabulator is, and what its
sign might be. If it is the horizontal-tab character HT ("\t") as
others have assumed, its sign is moot, at best. (This may be an
English-language problem -- 'sign' means '+' or '-'; maybe you mean
'symbol' or 'value', in which case the other answers will do.)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 24 Jul 1999 19:31:35 -0400
From: Floyd Morrissette <Floyd@NewWebSite.com>
Subject: Re: Submitting Photos
Message-Id: <379A4CD7.C1927BD1@NewWebSite.com>
Abigail wrote:
>
> Trevor Milley (jac@rom.com) wrote on MMCLII September MCMXCIII in
> <URL:news:3799b1e4.105698050@news.thezone.net>:
> .. I'm trying to develop a photo gallery on a website and I'm wondering
> .. if it is possible for people to give the path to their photo on their
> .. hard drive and for the script to copy that file to a database on the
> .. server. The only other option I can think of is getting the people to
> .. just email the photos in but I would prefer to have a script do it
> .. instead. If anyone can help it would be greatly appreciated.
>
> Well, yes, that's certainly possible.
>
> It's not the way I would do it though.
>
> Abigail
> --
> perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'
>
> -----------== 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 ==-----
Abigail I am genuinely interested and not trying to be smart or anything. If
that is not the way to do what would you suggest?
Floyd
------------------------------
Date: 24 Jul 1999 18:52:29 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Submitting Photos
Message-Id: <slrn7pkkcl.41s.abigail@alexandra.delanet.com>
Floyd Morrissette (Floyd@NewWebSite.com) wrote on MMCLIII September
MCMXCIII in <URL:news:379A4CD7.C1927BD1@NewWebSite.com>:
{}
{} Abigail wrote:
{} >
{} > Trevor Milley (jac@rom.com) wrote on MMCLII September MCMXCIII in
{} > <URL:news:3799b1e4.105698050@news.thezone.net>:
{} > .. I'm trying to develop a photo gallery on a website and I'm wondering
{} > .. if it is possible for people to give the path to their photo on their
{} > .. hard drive and for the script to copy that file to a database on the
{} > .. server. The only other option I can think of is getting the people to
{} > .. just email the photos in but I would prefer to have a script do it
{} > .. instead. If anyone can help it would be greatly appreciated.
{} >
{} > Well, yes, that's certainly possible.
{} >
{} > It's not the way I would do it though.
{}
{} Abigail I am genuinely interested and not trying to be smart or anything. If
{} that is not the way to do what would you suggest?
Well, for starters, I wouldn't quote signatures and advertisement
when quoting someones postings. That's pointless and a waste.
I would make use of HTTPs PUT command, use FTP PUT, or make use of
the file upload thingy some browser implement. Of course, none of
them have any relevance to this group.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
-----------== 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: 24 Jul 1999 17:11:29 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Using FAQ in ActiveStates Perl
Message-Id: <slrn7pkefa.3sr.abigail@alexandra.delanet.com>
Jody Fedor (JFedor@datacom-css.com) wrote on MMCLIII September MCMXCIII
in <URL:news:7ndamb$qpm$1@plonk.apk.net>:
.. How can I get "More" to work at the command line for Active States Perl
.. Docs.
That's not a Perl question. Call Microsoft Tech Support.
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
-----------== 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: Sat, 24 Jul 1999 16:09:57 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Variables in Regx?
Message-Id: <MPG.1203e794ea00b135989d3a@nntp.hpl.hp.com>
In article <slrn7pk3ss.3ja.abigail@alexandra.delanet.com> on 24 Jul 1999
14:11:00 -0500, Abigail <abigail@delanet.com> says...
> Argouarch (argouarc@idiom.com) wrote on MMCLIII September MCMXCIII in
> <URL:news:argouarc-2407991048240001@argouarc.dial.idiom.com>:
> == Here's the problem, I have a dictionary flat file with 30 000 lines, I
> == want to bold every instance of the defined word in each definition so my
> == regular expresion has to change for each line (sure dont want to do this
> == by hand, and was'nt PERL designed just for this crap :=)?.
> == I also want the html tags inserted in the file itself so I wrote a simple
> == utility script to change the file.
What is shown here doesn't change the file. It just changes the value
of $_ each time through the loop. You have to print the value to
another file. See perlfaq5: "How do I change one line in a file/delete
a line in a file/insert a line in the middle of a file/append to the
beginning of a file?"
> == I tried this:
> == Open...
> == While (<FILE>){
Perl keywords are all lower-case.
> == ($key,$translation)=split(/:/);
> ==
> == s/(${$key})/<b>$1<\/b>/g;
> == }
> ==
> == would not work... although I am forcing dereferencing of $key, (I also
> == tried dereferencing on both side and naively a /$key/<b>$key<\/b>/). It
> == seems that perl allows variables only on the left side like with the
> == modifiers e and ee ?!?
> == Am I missing something here?
>
> Why are you trying to dereference $key? What goes wrong with
>
> s{$key}{<b>$key</b>}g;
A lot goes wrong if $key contains regex metacharacters. And this has to
compile a regex for each line. And the /g modifier is superfluous. And
the split is unnecessary.
while (<FILE>) {
s|([^:]+):|<b>$1</b>:|;
print OUTFILE;
}
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 24 Jul 1999 16:49:17 -0800
From: argouarc@idiom.com (Argouarch)
Subject: Re: Variables in Regx?
Message-Id: <argouarc-2407991649170001@argouarc.dial.idiom.com>
>
> A lot goes wrong if $key contains regex metacharacters. And this has to
> compile a regex for each line. And the /g modifier is superfluous. And
> the split is unnecessary.
>
> while (<FILE>) {
> s|([^:]+):|<b>$1</b>:|;
> print OUTFILE;
> }
oh well I was just geting tired at 2am, did not think strait anymore, it
came back to me just now and your answer confirm it, only need to remember
the first term and match, no need to bother with variables at all ,I do
print out but did not copied the line in the post. Sorry about the
confusion. Next time I will wait before posting.
Philippe
------------------------------
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". 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 V9 Issue 246
*************************************