[16742] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4154 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 28 18:05:56 2000

Date: Mon, 28 Aug 2000 15:05:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <967500328-v9-i4154@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 28 Aug 2000     Volume: 9 Number: 4154

Today's topics:
    Re: basic question (David H. Adler)
    Re: Bulk add to a hash.. Any ideas? (Jakob Schmidt)
    Re: Counting across multiple lines? (Abigail)
    Re: directory where perl script is <johan.brattemark@net2000.ch>
    Re: errno 22 1024 char limit writing to DB's perlnewbie@my-deja.com
    Re: Evenlog module <carvdawg@patriot.net>
        Executable file creating executable file -- doesn't wor joshfeingold@my-deja.com
        File access over a network <kliquori@my-deja.com>
        fregb <lds@i-55.com>
        Get ip-adress of webserver <irmo@mailroom.com>
        Get own machine's dial-up IP address? <rgparker@west.net>
    Re: Get own machine's dial-up IP address? <rgparker@west.net>
    Re: Get own machine's dial-up IP address? <bcaligari@shipreg.com>
    Re: Global symbol "$dbh" requires explicit package name <ren.maddox@tivoli.com>
    Re: hard reference to subroutines from a hash variable (Abigail)
    Re: Help Calling A Function!!!! houseofpain@my-deja.com
    Re: how about programming a mud driver in Perl? (Abigail)
    Re: How can I find an images size?? <lr@hpl.hp.com>
    Re: How do I manipulate each element of an array? (Abigail)
    Re: How do I manipulate each element of an array? <lr@hpl.hp.com>
    Re: How do I manipulate each element of an array? <bart.lateur@skynet.be>
    Re: How do I manipulate each element of an array? (Craig Berry)
    Re: How do I manipulate each element of an array? (Craig Berry)
    Re: How do I manipulate each element of an array? <bart.lateur@skynet.be>
    Re: How do I manipulate each element of an array? lurker65535@my-deja.com
        How to encode for the web? <mahnke@uni-freiburg.de>
    Re: How to encode for the web? arjenwiersma@my-deja.com
    Re: How to encode for the web? arjenwiersma@my-deja.com
    Re: How to encode for the web? (Eric Bohlman)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 28 Aug 2000 21:16:30 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: basic question
Message-Id: <slrn8qllle.cv3.dha@panix2.panix.com>

On Mon, 28 Aug 2000 12:43:17 +0200, Alan J. Flavell
<flavell@mail.cern.ch> wrote:

>On 28 Aug 2000, Abigail wrote:
>
>> Well, noone knows what PERL is, as PERL was never created.
>
>http://support.microsoft.com/support/kb/articles/Q164/6/72.asp
>
>"IE Does Not Interpret PERL Scripts Correctly as Plain Text", is what
>MS calls it.  So it seems that somebody must have created "PERL"  ;-}

Not at all.  If one s/PERL/FROBNZR/ in that statement (and for the
sake of argument, let's posit that the well known FROBNZR language
doesn't actually exist... :-), it would be true as well.  I imagine
that IE also is incapable of interpreting the infinite void(tm) as
well... :-)

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Now everyone, grep your pod, and we'll begin..." - John Porter in
<357FD9DB.2109@min.net>


------------------------------

Date: Mon, 28 Aug 2000 20:36:22 +0200
From: sumus@aut.dk (Jakob Schmidt)
Subject: Re: Bulk add to a hash.. Any ideas?
Message-Id: <1eg3c1w.5yf1byndczegN@[192.168.88.117]>

brian d foy <brian@smithrenaud.com> wrote:

> In article <1eg2qv3.60p37ppyqryaN@[192.168.88.117]>, sumus@aut.dk (Jakob
> Schmidt) posted:
> 
> > I suppose you like
> 
> > In article <8oc336$8um$1@nnrp1.deja.com>,  <alphazerozero@my-deja.com>
> > wrote:
> > >$hash->{'key3'}="value3";  #however this
> > >$hash->{'key4'}="value4";  #does... But surely its more verbose than
> > 
> > better (from a readability perspective)?
> 
> are you being a smart-ass on purpose?

No. I wasn't even aware. Exactly why are you angry?

> i think
> it's much better to somehow put the keys next to the values.

And I pointed to the OPs code as an example of just that. This was
supposed to indicate that I can see your point. I didn't assume or in
any way mean to suggest that you wouldn't have been able to come up with
anything more clever than the OPs code.

After that I mentioned another way to do it which gives near optimum
readability. And you must have liked it since you say you would use it
yourself?

> as for wasting cycles, i think development and maintenance
> thought cycles should count as well.

I never said anything about wasting cycles! I merely mentioned that some
would be spent. I even pointed out what we'd get in return for spending
them.

Now I know that generally there's no need to worry about cycles but I
still think it's a good thing to know about them. Sometimes they do
matter. I didn't mention the cycles to put down the "new" solution which
I think is just swell. And I didn't mention it to suggest that you
wouldn't have thought of it yourself. You're likely to know much more
about it than I. I mentioned them so that one day when the OP (or
somebody else who might have read the thread and who knows even less
than I do) finds himself merging hashes in a cycle critical situation,
he'll remember to think twice about this way of doing it.

That's how nice I am - and you're calling me a smartass! What's the
world and usenet coming to?

> if you are worreid about
> a tight memory situation, Perl might not be the right tool.

I mentioned the extra variable but didn't even worry enough to make it
temporary as you do.

-- 
Jakob


------------------------------

Date: 28 Aug 2000 18:59:07 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Counting across multiple lines?
Message-Id: <slrn8qldib.bbg.abigail@alexandra.foad.org>

Pedro A Navarro (pnavarro@uswest.net) wrote on MMDLIII September MCMXCIII
in <URL:news:39A8981B.47000002@uswest.net>:
// Hi:
// 	I'm new to Perl and programming in general, so I'm stumped by a simple
// problem. I'm trying to write a program that counts the number of
// characters in a file, such as 
// 
// >header
// TADSTWTASRTDRAFTARSGRQWTS
// AGSTDRASGATFSASDGTASTTAGS
// TQTRAEWSTATSGATSGTASTATST
// 
// That is for a protein sequence file, in case you are wondering. When I
// use
// 
// $count=tr/A-Z//;
// print "$count\n";
// 
// I get the number of characters for each line, instead of for the whole
// thing. I have tried to get rid of the newline character with
// 
// $count=tr/\n//d;
// 
// but that gives me a count of "1" for each line, and I still have
// multiple lines!
// How do I get rid of the newline character, or at the very least, how do
// I join the multiple lines so I have one single string? I'm fairly sure
// this is a simple thing to do, but so far I don't know what else to try!


Here are some short programs:

    perl -wle 'no warnings "numeric"; $file = "whatever";
               print `wc -c $file` - `wc -l $file`'

    perl -nle '$s .= length; END {print $s}' whatever



Abigail
               
-- 
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");


------------------------------

Date: Mon, 28 Aug 2000 23:57:31 +0200
From: "Johan Brattemark" <johan.brattemark@net2000.ch>
Subject: Re: directory where perl script is
Message-Id: <8oemn0$4g0$1@news.swissonline.ch>


"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8qkq7r.sk8.mgjv@martien.heliotrope.home...
> On Mon, 28 Aug 2000 12:48:07 GMT,
> Eric BULEON <beric20@my-deja.com> wrote:
> > Hello
> >
> > I want to know in which directory the currently running Perl script
is.
> > How can I do that ?
>
> Your question is ambiguous:
>
> Do you
>
> 1) Want to find out in which directory your program is running?
>
>     use the Cwd module
>
>     perldoc Cwd
>
> 2) Want to find out in which directory the sources of your program
live?
>
>     This is answered in the FAQ documentation:
>
>     perldoc perlfaq8
>     [snip]
>         How do I add the directory my program lives in to the mod­
>         ule/library search path?
>     [snip]
>
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | Hi, Dave here, what's the root
> Commercial Dynamics Pty. Ltd.   | password?
> NSW, Australia                  |


Try this:

($dir) = $0 =~ /(.*)\\.*/;  # WinNT
($dir) = $0 =~ /(.*)\/.*/;  # Unix

Johan





------------------------------

Date: Mon, 28 Aug 2000 21:01:54 GMT
From: perlnewbie@my-deja.com
Subject: Re: errno 22 1024 char limit writing to DB's
Message-Id: <8oejvk$4io$1@nnrp1.deja.com>

  I just wanted to share with anyone who is interested, the solution I
found for the problem encountered below.
  I modified the source code for SDBM_File by modifing two lines of
code in "\AP616_source\ext\SDBM_File\sdbm\SDBM_File.h".

  Lines of code changed:
  #define PBLKSIZ 4096    /* original size 1024 */
  #define PAIRMAX 4080    /* original size1008 *//* arbitrary on
PBLKSIZ-N */

After I made these changes I simply recompiled the source code and
moved the files to the "\Perl\lib\auto\SDBM_File" directory.




In article <8nugl8$1ul$1@nnrp1.deja.com>,
  perlnewbie@my-deja.com wrote:
> I am encountering an error when I try and write to a DB file in WinNT
> using Active Perl. Here is the error message I receive:
>
> "Tue Aug 22 09:54:07 2000: sdbm store returned -1, errno 22,
> key "92"..."
>
> It seems that I am only allowed to write a maximum of 1024 characters.
> I was wondering if there is any way to work around this limitation?
> Below is a code snippet of the function which is writing to the DB
> file.  By the way I am not the original author of this code I am just
> trying to migrate an existing site in Unix environment to WinNT.
Don't
> ask why.  I didn't sell the customer on the idea I just got stuck with
> the mess.
>
> use Fcntl;
> use AnyDBM_File;
> use strict;
>
> package DB;
>
> sub createRecipe {
> 	my($data)=@_;
> 	my($recdata)=join($DB::delim,map {$data->{$_}} @DB::fields);
> 	my($id)=$data->{'id'};
>
> 	&::timeout_write_lock("DB::DBMFILE", $config::recipedbm);
> 	dbmopen(%DB::RECIPEDBM, $config::recipedbm, 0644)
> 		|| &Fatal("dbmopen of $config::recipedbm: $!\n");
> 	$DB::RECIPEDBM{$id}= $recdata;
>
> 	dbmclose(%DB::RECIPEDBM);
> 	 &::unlock("DB::DBMFILE");
> 	close("DB::DBMFILE");
>
>  	&Almond::Log("Created REC#$id: $data->{'name'} EOF =
> $endofline");
> }
>
> Thanks in advance for any help I can get.  I am stuck!
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 28 Aug 2000 14:27:24 -0400
From: H C <carvdawg@patriot.net>
Subject: Re: Evenlog module
Message-Id: <39AAAF0C.DD16E81C@patriot.net>

http://www.forixnt.com/tools.html has several scripts that retrieve EventLog
info,
one of which may be of help to you.

Johan wrote:

> I wrote a script to get the eventlog records from several machines. All
> fields in the hash are filled correct except the 'user' field. Anybody else
> who came across this problem and found a solution? I'm working with
> Activestate Perl build 5.6.0 build 616
> thanks in advance,
> Johan

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




------------------------------

Date: Mon, 28 Aug 2000 18:30:47 GMT
From: joshfeingold@my-deja.com
Subject: Executable file creating executable file -- doesn't work
Message-Id: <8oeb4n$pdd$1@nnrp1.deja.com>

Here is my scenario:

I have a file "parent.pl" which creates a file "child.pl". The problem
is that when parent.pl is run and creats child.pl via the Internet the
file is put in the Unix group "staff" which is not executable by me.
How can I make a file which can be executed and have permissions
changed by me?

Thanks,
Josh


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 28 Aug 2000 19:21:38 GMT
From: kliquori <kliquori@my-deja.com>
Subject: File access over a network
Message-Id: <8oee39$t8e$1@nnrp1.deja.com>

I'm trying to write a Perl script to access files on different UNIX
boxes. I want to be able to search through /etc/passwd on three
different boxes. I would like, however, to avoid using shell commands
if possible. I see one of two ways:
1) Use NFS and access the file as if it's local.
2) Use rcp with the system command to copy the files locally.

Are there any other ways to do this?

TIA
 ...Kevin


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 28 Aug 2000 15:50:10 -0700
From: "lds" <lds@i-55.com>
Subject: fregb
Message-Id: <0nAq5.94943$dC1.128375@dfw-read.news.verio.net>

gfjkmuyjnh




------------------------------

Date: Mon, 28 Aug 2000 20:04:02 GMT
From: Irmo <irmo@mailroom.com>
Subject: Get ip-adress of webserver
Message-Id: <8oegj3$g0$1@nnrp1.deja.com>

Hi

Is there any way to get the ip adress of the server, a (perl) script is
running on ?


/Irmo


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 28 Aug 2000 20:50:08 GMT
From: Randall Parker <rgparker@west.net>
Subject: Get own machine's dial-up IP address?
Message-Id: <MPG.14147162c4575c0c9898f1@news.onlynews.com>

Suppose a machine has a permanent (or even dynamic) IP address it uses on 
a local network. But suppose in addition it gets a dynamic IP address 
handed to it every time it does dial-up to an ISP using a phone modem or 
cable modem or DSL modem.

Okay, the question is, how to find out what that second IP address is? 

My goal is to have some machine sitting at home that is connected via 
auto-dial phone modem or cable modem at a certain time of the day 
(using a Perl script of course) to  connect to the internet, find out its 
dynamic IP address, and then connect to a machine I have at work (that 
has a static IP address) and tell it what the dynamic IP address is. 

If possible I'd like to do this in a portable way that will work across 
Linux, OS/2, and NT. A friend has an OS/2 box and he and I both want to 
do this. 

Alternatively: Suppose the home machine just went and made the socket 
connection to the work machine. Then could the work machine see from the 
socket connection object what IP address it is coming from?

Even if the latter would work I'd still like a better way to find out a 
machine's own IP address(es). 



------------------------------

Date: Mon, 28 Aug 2000 21:27:38 GMT
From: Randall Parker <rgparker@west.net>
Subject: Re: Get own machine's dial-up IP address?
Message-Id: <MPG.14147a2bc75060249898f2@news.onlynews.com>

For one of the questions below (how to get the IP address of the remote 
process that connects to your socket) I found:
    ($port, $iaddr) = sockaddr_in(getpeername(Socket_Handle));

But why get the peer name before calling sockaddr_in? What if the remote 
connecting node does not have a name? What if it only has an IP address? 
Will this still work?

On Mon, 28 Aug 2000 20:50:08 GMT esteemed Randall Parker did'st hold 
forth thusly:
> Suppose a machine has a permanent (or even dynamic) IP address it uses on 
> a local network. But suppose in addition it gets a dynamic IP address 
> handed to it every time it does dial-up to an ISP using a phone modem or 
> cable modem or DSL modem.
> 
> Okay, the question is, how to find out what that second IP address is? 
> 
> My goal is to have some machine sitting at home that is connected via 
> auto-dial phone modem or cable modem at a certain time of the day 
> (using a Perl script of course) to  connect to the internet, find out its 
> dynamic IP address, and then connect to a machine I have at work (that 
> has a static IP address) and tell it what the dynamic IP address is. 
> 
> If possible I'd like to do this in a portable way that will work across 
> Linux, OS/2, and NT. A friend has an OS/2 box and he and I both want to 
> do this. 
> 
> Alternatively: Suppose the home machine just went and made the socket 
> connection to the work machine. Then could the work machine see from the 
> socket connection object what IP address it is coming from?
> 
> Even if the latter would work I'd still like a better way to find out a 
> machine's own IP address(es). 
> 
> 


------------------------------

Date: Tue, 29 Aug 2000 00:03:19 +0200
From: "Brendon Caligari" <bcaligari@shipreg.com>
Subject: Re: Get own machine's dial-up IP address?
Message-Id: <8oemu4$d26$1@news.news-service.com>

"Randall Parker" <rgparker@west.net> wrote in message
news:MPG.14147162c4575c0c9898f1@news.onlynews.com...
> Suppose a machine has a permanent (or even dynamic) IP address it uses on
> a local network. But suppose in addition it gets a dynamic IP address
> handed to it every time it does dial-up to an ISP using a phone modem or
> cable modem or DSL modem.
>
> Okay, the question is, how to find out what that second IP address is?
>
> My goal is to have some machine sitting at home that is connected via
> auto-dial phone modem or cable modem at a certain time of the day
> (using a Perl script of course) to  connect to the internet, find out its
> dynamic IP address, and then connect to a machine I have at work (that
> has a static IP address) and tell it what the dynamic IP address is.
>
> If possible I'd like to do this in a portable way that will work across
> Linux, OS/2, and NT. A friend has an OS/2 box and he and I both want to
> do this.
>

at the win2000 console, if i type 'ipconfig', i get a
clear picture of what IPs my machine talks on.  If I wanted
to know what IP I have been assigned I could...say..send that
information to the office email address (if all one needs to
know is what IP his home pc is on so that he could upload all
the downloaded mp3s onto his home computer).

Brendon





------------------------------

Date: 28 Aug 2000 14:20:11 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Global symbol "$dbh" requires explicit package name at   d:\...\Behzad.pl line 17.
Message-Id: <m34s455h1w.fsf@dhcp11-177.support.tivoli.com>

jason <elephant@squirrelgroup.com> writes:

> the other point I was making was that if you're going to use a variable 
> in an 'or die' construct then you must have already declared it (and 
> ideally initialised it as well) because if the thing that you're testing 
> fails then the word will not be declared and you will get errors from 
> strict

My perl agrees with you, though I find it odd... Base on the
precedence table, "=" binds more tightly than "or", so one (me) would
think that the variable would be declared before the "die".

However, I quick Deparse gave what I considered to be surprising
results:

% perl -MO=Deparse -e 'use strict; my $x = 0 or die "blah $x\n";'
Global symbol "$x" requires explicit package name at -e line 1.
-e had compilation errors.
die "blah ${'x'}\n" unless my $x = 0;


Now, I was aware that this construct (or, more particularly, the
reversed construct "my $x = 0 unless undef;") resulted in the variable
not being declared, but I had no idea that the use of "or" in a
declaration would get so turned around.

It seems to get even stranger... if you force the "or" to be in a
context were it cannot simply be reworked into a conditional, then you
get something that Deparses into "||", as I would expect.  However,
this does not get read of the problem.  For example:

use strict;
my $y = (my $x = 0 or die "blah $x\n");

Deparses into:
my $y = (my $x = 0) || die("blah ${'x'}\n");


which, as the "${'x'}" syntax would indicate, still gets an error
under "strict".

This all just seems wrong....

-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: 28 Aug 2000 19:35:12 GMT
From: abigail@foad.org (Abigail)
Subject: Re: hard reference to subroutines from a hash variable
Message-Id: <slrn8qlfm0.bbg.abigail@alexandra.foad.org>

lds (lds@i-55.com) wrote on MMDLIII September MCMXCIII in
<URL:news:qGYp5.80000$dC1.118991@dfw-read.news.verio.net>:
,, I'm very very new to perl. I do have a copy of the camel book, however i
,, just ca't figure this out. Would someone comment on whether or not this
,, would work:
,, 
,, $user_data{time_at_post} =  \&time_now


Did you try? If no, why not? If yes, did it work? 


Abigail
-- 
perl -wle 'print "Prime" if (0 x shift) !~ m 0^\0?$|^(\0\0+?)\1+$0'


------------------------------

Date: Mon, 28 Aug 2000 18:15:28 GMT
From: houseofpain@my-deja.com
Subject: Re: Help Calling A Function!!!!
Message-Id: <8oea7c$o9h$1@nnrp1.deja.com>

In article <39AAA1B4.922B15D2@texas.net>,
  Tom Briles <sariq@texas.net> wrote:
> houseofpain@my-deja.com wrote:
> >
> > In article <9Vvq5.12287$d8.2648797@typhoon.southeast.rr.com>,
> >   "Philip Garrett" <philipg@atl.mediaone.net> wrote:
> > > <houseofpain@my-deja.com> wrote in message
> > > news:8oduu6$a09$1@nnrp1.deja.com...
> > > [snip]
> > > > my $function = "foo";
> > > >
> > > > I want to be able to say $this->$function, but perl does not
seem to
> > > > like that.  Does anyone know how to do this.
> > >
> > > This may not the most graceful solution, but it works:
> > >
> > > my $function = 'foo';
> > > eval "\$this->$function";
> > >
> >
> > Best answer I've heard so far.  Thanks
>
> How could you possibly think that 'eval EXPR' is better than Greg
> Bacon's answer to your question the last time you posted it?
>
> "If you want to call a method whose name is in $meth, do this
>
>      $obj->$meth();
>
> "For this particular form, you have to use a scalar (as opposed to an
> expression yielding a scalar), and the parentheses are mandatory."
>
> - Tom
>

You are correct tom, i could not get it to work the way greg said
because i did not use the parentheses.  So thank you greg and tom for
the best answer i've heard.

-josh


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 28 Aug 2000 19:41:41 GMT
From: abigail@foad.org (Abigail)
Subject: Re: how about programming a mud driver in Perl?
Message-Id: <slrn8qlg26.bbg.abigail@alexandra.foad.org>

Nick Maxwell (maxwelln@purdue.edu) wrote on MMDLIV September MCMXCIII in
<URL:news:8od46s$d3n$1@mozo.cc.purdue.edu>:
@@ Is this a feasible thing to do?  I ordered the Perl Black Book and
@@ Writing More Effective Perl Programs so I could learn the language with the
@@ eventual goal of programming systems for MUDs and their drivers.  I would
@@ love some input, ideas, or suggestions toward this end.


That entirely depends on what kind of mud driver, and what you provide
to your coders.

If it's like an LP system, where you can modify the game from within
the game, with total strangers being able to code (wizards), and you
provide Perl as the building language, then Perl is totally unsuitable,
for two reasons. First, it gives you access to the system, and second,
it's way to trivial to write something that will never terminate.

However, if you either only have trusted coders, or you use Perl to
write just the driver and another language to build the mud (that is,
you write the compiler/interpreter in Perl), Perl is suitable. However,
there is always the need for speed in muds. And muds tend to gobble up
huge amounts of RAM; the more RAM they can use, the better. Perl does
not do well compared to C in those departments.

I'd just stick with DGD.... 


Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


------------------------------

Date: Mon, 28 Aug 2000 11:35:54 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How can I find an images size??
Message-Id: <MPG.141450e2abefeee098ace5@nntp.hpl.hp.com>

In article <slrn8qimrq.60u.clay@panix3.panix.com> on 27 Aug 2000 
18:18:34 GMT, Clay Irving <clay@panix.com> says...

 ...

> This function will also return the size of a GIF image:

I doubt that.  And I doubt that you ever tested it before posting it.

> sub sizegif {
>     my $filename = @_;

What is the result of assigning an array to a scalar?

>     open GIF, "$filename" or die "Error $file: $!\n";

The quotes are superfluous, and $file isn't declared.

Where is the 'binmode GIF;' that is necessary in some environments and 
harmless in the others?

>     sysread(GIF, $header, 13) or die "sysread header: $!";
>     ($gif, $width, $height) = unpack('a3x3vv', $header);
> };

In fact, except for the incorrectly assigned $filename, none of the 
variables is declared.

But the unpack format is correct.  Congratulations.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 28 Aug 2000 19:43:17 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How do I manipulate each element of an array?
Message-Id: <slrn8qlg56.bbg.abigail@alexandra.foad.org>

Lincoln Marr (lincolnmarr@nospam.europem01.nt.com) wrote on MMDLIV
September MCMXCIII in <URL:news:8od8tj$hd$1@qnsgh006.europe.nortel.com>:
--
-- $x =1;
-- foreach (@array) {
--  if ($array[$x] eq "") { $array[$x] = "&nbsp;" ; }
-- ++$x;
-- }
--
-- but then what happens once you've reached the end of the array? Any
-- thoughts??


Well, what *did* happen when you tried?


However, regardless of the above question, what did you find in the
manual about 'foreach'?


Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


------------------------------

Date: Mon, 28 Aug 2000 12:35:56 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <MPG.14145ef54ce6173098ace8@nntp.hpl.hp.com>

In article <m38zth5phc.fsf@dhcp11-177.support.tivoli.com> on 28 Aug 2000 
11:18:07 -0500, Ren Maddox <ren.maddox@tivoli.com> says...
 ...

> $_ eq '' and $_ = '&nbsp;' for @array;

Finally approaching a minimal-length correct solution.

  length or $_ = '&nbsp;' for @array;

or (using Abigail's 'length' horror and squeezing out legibility):

  y===c or$_='&nbsp;'for@array;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Mon, 28 Aug 2000 20:12:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <4rhlqs4hmdv0dg5hd2rmnbk91uj8qhb6gk@4ax.com>

Lincoln Marr wrote:

>$x =1;
>foreach (@array) {
> if ($array[$x] eq "") { $array[$x] = "&nbsp;" ; }
>++$x;
>}

Change $_ which is an alias to each array element in turn.

	foreach(@array) {
	    $_ = '&nbsp;' unless defined && length;
	}

-- 
	Bart.


------------------------------

Date: Mon, 28 Aug 2000 20:26:17 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How do I manipulate each element of an array?
Message-Id: <sqlin93ht9161@corp.supernews.com>

Jakob Schmidt (sumus@aut.dk) wrote:
: As usual with perl the solution is much simpler. the $_ in a foreach
: loop works as a reference to the arrayvalue so you just need
: 
: foreach ( @array ) { $_ or $_ = '&nbsp;' }

You can even golf that down to

  foreach ( @array ) { $_ ||= '&nbsp;' }

Or, rearranging and going for max compression,

  $_ ||= '&nbsp' for @array;

That ||= idiom is a great way to supply default values, iff the various
flavors of falsness aren't themselves potentially valid non-default
values.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


------------------------------

Date: Mon, 28 Aug 2000 20:28:51 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How do I manipulate each element of an array?
Message-Id: <sqlis35pt9155@corp.supernews.com>

Larry Rosler (lr@hpl.hp.com) wrote:
: or (using Abigail's 'length' horror and squeezing out legibility):

I hereby nominate "Abigail's Length Horror" to take its just place as a
canonical Perl community term, alongside the Schwartzian and GR transforms
and other honored hacks.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


------------------------------

Date: Mon, 28 Aug 2000 21:16:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How do I manipulate each element of an array?
Message-Id: <nlllqs8l2u97b67iaf7m4ju62vhojfbm9g@4ax.com>

Craig Berry wrote:

>: foreach ( @array ) { $_ or $_ = '&nbsp;' }
>
>You can even golf that down to
>
>  foreach ( @array ) { $_ ||= '&nbsp;' }
>
>Or, rearranging and going for max compression,
>
>  $_ ||= '&nbsp' for @array;

Any reason for replacing every zero with a non-breaking space?

-- 
	Bart.


------------------------------

Date: Mon, 28 Aug 2000 21:28:11 GMT
From: lurker65535@my-deja.com
Subject: Re: How do I manipulate each element of an array?
Message-Id: <8oelgi$6k6$1@nnrp1.deja.com>

In article <8od8tj$hd$1@qnsgh006.europe.nortel.com>,
  "Lincoln Marr" <lincolnmarr@nospam.europem01.nt.com> wrote:
> I'm having a little trouble at getting at all elements of an array at
the
> same time.... I'm no perl wizard so this is probably pretty simple.
>
> All I want to do is say 'foreach element of @array, if the element is
empty
> then set it to &nbsp; otherwise leave it as it is'.
>
How about:

map { s/^$/&nbsp;/ } @array;

perldoc -f map


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 28 Aug 2000 21:29:12 +0100
From: "Christian Mahnke" <mahnke@uni-freiburg.de>
Subject: How to encode for the web?
Message-Id: <8oee88$9ng$1@n.ruf.uni-freiburg.de>

I try to post the following information:

infos="<form action="/cgi-bin/pascale"><input type hidden name=sessionid
value="1234234"</form>"

Obviously I have to encode this, but how? (I heard something about
hexadecimal)

Thanks for your help




------------------------------

Date: Mon, 28 Aug 2000 21:17:30 GMT
From: arjenwiersma@my-deja.com
Subject: Re: How to encode for the web?
Message-Id: <8oeksm$5so$1@nnrp1.deja.com>

You probably want to do something like this:

$infos=qq{<form action="/cgi-bin/pascale"><input type hidden
name=sessionid value="1234234"</form>}

this way you wont need to escape the "'s.

Arjen

In article <8oee88$9ng$1@n.ruf.uni-freiburg.de>,
  "Christian Mahnke" <mahnke@uni-freiburg.de> wrote:
> I try to post the following information:
>
> infos="<form action="/cgi-bin/pascale"><input type hidden
name=sessionid
> value="1234234"</form>"
>
> Obviously I have to encode this, but how? (I heard something about
> hexadecimal)
>
> Thanks for your help
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 28 Aug 2000 21:35:25 GMT
From: arjenwiersma@my-deja.com
Subject: Re: How to encode for the web?
Message-Id: <8oelur$732$1@nnrp1.deja.com>

And btw,

This you can just put into a HTML file and feed it to the browser,
there is no encoding needed...

Arjen

In article <8oeksm$5so$1@nnrp1.deja.com>,
  arjenwiersma@my-deja.com wrote:
> You probably want to do something like this:
>
> $infos=qq{<form action="/cgi-bin/pascale"><input type hidden
> name=sessionid value="1234234"</form>}
>
> this way you wont need to escape the "'s.
>
> Arjen
>
> In article <8oee88$9ng$1@n.ruf.uni-freiburg.de>,
>   "Christian Mahnke" <mahnke@uni-freiburg.de> wrote:
> > I try to post the following information:
> >
> > infos="<form action="/cgi-bin/pascale"><input type hidden
> name=sessionid
> > value="1234234"</form>"
> >
> > Obviously I have to encode this, but how? (I heard something about
> > hexadecimal)
> >
> > Thanks for your help
> >
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 28 Aug 2000 21:58:06 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: How to encode for the web?
Message-Id: <8oen9e$isd$5@nntp9.atl.mindspring.net>

arjenwiersma@my-deja.com wrote:
: And btw,
: 
: This you can just put into a HTML file and feed it to the browser,
: there is no encoding needed...
: 
: Arjen
: 
: In article <8oeksm$5so$1@nnrp1.deja.com>,
:   arjenwiersma@my-deja.com wrote:
: > You probably want to do something like this:
: >
: > $infos=qq{<form action="/cgi-bin/pascale"><input type hidden
: > name=sessionid value="1234234"</form>}
: >
: > this way you wont need to escape the "'s.

In this specific case, there's no encoding required, but in the general 
case, there are two forms of encoding that may be needed:

1) In HTML, literal ampersands need to be replaced with &amp; regardless 
of where they occur, and literal less-than signs need to be replaced with 
&lt; if they occur in the content of elements (in XHTML, they need to be 
replaced everywhere they occur, even in attribute values).

2) In attribute values that are supposed to hold URLs (e.g. href values), 
many non-alphanumeric characters need to be encoded as a '%' followed by 
a 2-digit hex value.  This includes spaces.

CGI.pm has functions to do both kinds of encoding.



------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4154
**************************************


home help back first fref pref prev next nref lref last post