[7866] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1491 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 17 18:07:28 1997

Date: Wed, 17 Dec 97 15:00:32 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 17 Dec 1997     Volume: 8 Number: 1491

Today's topics:
     6 elementary questions <xah@best.com>
     Re: 6 elementary questions <eike.grote@theo.phy.uni-bayreuth.de>
     Access Log <hvanlint@lodestar.be>
     ANNOUNCE: News-Scan 0.50 (Greg Bacon)
     append to top of file ? <cottage@azmail.net>
     Re: closures and sort (Chad Lake)
     Cmd-Line perl via rsh <mjforder@hotmail.com>
     Re: Cmd-Line perl via rsh (Honza Pazdziora)
     Re: compacting array (Figured it out) (Sitaram Chamarty)
     Re: CR/LF Text-File (Tad McClellan)
     error when using OPEN(FILE...) under ms iis 2.0 markus.rietzler@rzf.nrw.de
     Re: failed to close pipe into sendmail (Keith Willis)
     flow control <prl2@lehigh.edu>
     Re: Framework for building custom HTTP servers? <dsill@sws5.ctd.ornl.gov>
     Re: Framework for building custom HTTP servers? (Chip Salzenberg)
     Re: getting the pid from a system call <kerenw@amdocs.com>
     Re: help with hash error (Andrew M. Langmead)
     Re: HELP! How to use records in Perl? <freter@heorotsi.com>
     Re: How get which day is in the week? (brian d foy)
     Re: How to get everything in between <pre>....</pre> ta (Frank)
     Re: How to get everything in between <pre>....</pre> ta (Neil Burnett)
     Re: how to send entire script code to STDOUT if STDIN e (Andrew M. Langmead)
     Re: how to send entire script code to STDOUT if STDIN e (Bart Lateur)
     JPL & PERL 5.004_04 under IRIX <bugaj@bell-labs.com>
     Re: LWP for Windows (Chip Salzenberg)
     Re: NEED:  Fast, Fast string trim() (Tony Bowden)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 17 Dec 1997 03:30:44 -0800
From: "Xah" <xah@best.com>
Subject: 6 elementary questions
Message-Id: <678csr$75s$1@nntp1.ba.best.com>

Some Perl beginner's questions I'v accumulated. I've not investigated them
extensively, but those experienced should be able to help me out easily.
Thanks.

# Question: How to explicitly force a conversion between number and string?
(if there's way.)

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

# Question: Why does the following returns 4 and 5, not all 5?

@array = (0 .. 9);
%hash = @array;
print 0 + %hash, "\n";
print 0 + keys(%hash), "\n";

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

# Question: in the following code, it seems that the second argument of
foreach is automatically converted into an array. Is this behavior somewhere
in man page?

    while (<>) {
        foreach $word (m/(\w+)/g) {
            # do something with $word here
        }
    }

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

# Question: explain the behavior of the following code. i.e. What is the
context of @a in print and when is a separator added automatically?

@a = (1 .. 10);
print "@a\n";
print @a;

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

# Question: Why the following two versions of code differ? one prints just
one line, the other prints the whole file.

print <FILE>;

$line = <FILE>;
print $line;

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

# Question: Suppose I want to split a string, and get the second element,
split it again and get the last element. What's the appropriate perl style
code? For example, $str = 'GET /~xah/Curves_dir/Spc.html HTTP/1.0', and I
want to split it by a space, then split the second element by a slash, then
taking the last element 'Spc.html' as result.

If I'm working with a functional language, then I can nest them something
like

(split(m@/@, (split(m@ @, $str))[2]))[-1]

but such code doesn't work in perl. I could write a series of assignments,
but I'm looking for a good perl style code.

PS I'm not asking for ways to extract Spc.html. I'm looking for perl codes
comparable to nested expressions in functional languages. (without creating
a bunch of variables on the side.)

 Xah, xah@best.com
 http://www.best.com/~xah/MathGraphicsGallery_dir/mathGraphicsGallery.html
 "perl my ass"


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

Date: Wed, 17 Dec 1997 15:45:11 +0100
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: 6 elementary questions
Message-Id: <3497E577.1CFB@theo.phy.uni-bayreuth.de>

Hi,

Chip Salzenberg wrote:
> 
> According to Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>:
> >Xah wrote:
> >> # Question: Why does the following returns 4 and 5, not all 5?
> >>
> >> @array = (0 .. 9);
> >> %hash = @array;
> >> print 0 + %hash, "\n";
> >
> >This value is NOT the number of elements (or keys), but has to do
> >something with the internal usage of the hash (see the camel book
> >for a short explanantion).
> 
> Well, it's a string consisting of the number of keys, and a slash,
> and the number of buckets.  As a number, it _is_ the number of keys.

As far as I can count, there are 5 keys, but %hash equals to '4/8' ...

Bye, Eike
-- 
=======================================================================
>>--->>    Eike Grote  <eike.grote@theo.phy.uni-bayreuth.de>    <<---<<
-----------------------------------------------------------------------
 Home Page, Address, PGP,...:  http://www.phy.uni-bayreuth.de/~btpa25/
-----------------------------------------------------------------------
 PGP fingerprint:      1F F4 AB CF 1B 5F 4B 1D 75 A1 F9 C5 7B 3F 37 06
=======================================================================


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

Date: Wed, 17 Dec 1997 11:04:05 +0100
From: "Hans Van Lint" <hvanlint@lodestar.be>
Subject: Access Log
Message-Id: <6787ph$q8j$1@news2.xs4all.nl>

Hi,

i have a script that shows me detailed information ( in html format) of the
access_log file.

Now, when I try this,

$logfile = "../logs/access_log";
open(best, $logfile) || "Error"

I get the following error:
 ../logs/access_log: Permission denied

But I'm sure access_log can be read by everyone: -rw-r--r-- (owner peabody -
if I was the owner it would be dbintein)

And when I try to read it with joe access_log it works!

Why can't perl read it with open();??

Any ideas??

Thank you very much...

Bye




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

Date: 17 Dec 1997 12:48:20 GMT
From: gbacon@pluto.cs.uah.edu (Greg Bacon)
Subject: ANNOUNCE: News-Scan 0.50
Message-Id: <678hmk$ds3$1@news1.teleport.com>

I have just uploaded to CPAN release 0.50 of the News-Scan distribution.
It should hit the mirrors within a few days, but the jittery among us
can pick up the distribution at

    http://www.cs.uah.edu/cs/students/gbacon/perl/News-Scan-0.50.tar.gz

The README follows:

Description
-----------

This is the Perl 5 News-Scan distribution.  It requires perl version 5.004
or later.

This distribution provides a mechanism for collecting articles from a
set of Usenet newsgroups and then creating statistical reports about
those groups.

IMPORTANT!!!  IMPORTANT!!!  IMPORTANT!!!  IMPORTANT!!!  IMPORTANT!!!
IMPORTANT!!!  IMPORTANT!!!  IMPORTANT!!!  IMPORTANT!!!  IMPORTANT!!!

This release of News-Scan is incompatible with prior releases.  This
should be considered alpha-quality software, so the internal
implementation is subject to change without notice, although I will
only make incompatible changes only when absolutely necessary.

Prerequisites
-------------

To use NewsScan, you need to have installed the following packages:

    TimeDate-#.##
    MailTools#.##
    IO-#.##

If you want to collect articles from an NNTP server, you'll also need
to install

    libnet-#.##

Installation
------------

Install NewsScan by running the following commands:

    perl Makefile.PL
    make
    make install

Examples
--------

Please see the eg/ directory after you have unpacked the distribution
for examples of using this library to gather and report statistics for
Usenet newsgroups.

Bugs, Problems, Suggestions
---------------------------

Please send any suggestions, bug reports, complaints, et cetera to
Greg Bacon <gbacon@cs.uah.edu>.

Acknowledgements
----------------

This software is based on Mike Lee's <mikey@ontek.com> posters
distribution and also on software posted to comp.lang.perl.misc
by Christian Murphy <cpm@muc.de>.

Many, many thanks are also in order to Gary Niemcewicz <gniemcew@dti.net>
for all his helpful thoughts, comments, and bug reports.

Chaim Frenkel <chaimf@cris.com> has also contributed immensely with his
extremely helpful comments, suggestions, and questions.

Copyright
---------

Copyright (c) 1997 Greg Bacon. All rights reserved.
This library is free software; you can distribute and/or modify it under
the same terms as Perl itself.

Enjoy,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF




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

Date: 17 Dec 1997 19:13:14 GMT
From: "Bob Zwick" <cottage@azmail.net>
Subject: append to top of file ?
Message-Id: <01bd0b1e$dffa7720$5f7d0cd1@cms>

Can anyone provide a simple script that add to the top of a file.
I tried seek, but I must be doing it wrong.
Don't have perl so I can't do a read doc.
Thanks
-- 
Bob Zwick - Cottage Micro Services
103 Vinyard Drive, WaxahachieTX 75167
(972) 435-2446 FAX/VOICE
http://www.cottagemicro.com


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

Date: 17 Dec 1997 16:35:59 GMT
From: clake@belay.cs.utah.edu (Chad Lake)
Subject: Re: closures and sort
Message-Id: <678v1f$ie9@magus.cs.utah.edu>

In article <677c5r$bth$1@csnews.cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:
>
>First, you can't use closures to bind up $a and $b.  They aren't
>lexicals; they're globals.  Closures close over lexicals.
>

Ah...I'll I found in the Camel was that $a and $b were passed in by
reference, not that they were global. I assume that it was done this
way so that a block could be used as the first argument to sort, I
guess. 

>An important thing to know is that $a and $b is the package
>the call to sort was compiled in.  If you say
>
>    package Dunno;
>    @x = sort Elsewhere::by_magic @y;
>
>Then the $a and $b used in &Elsewhere::by_magic are globals that are
>set in package Dunno.  Bizarre, perhaps even brain-damaged, but true.
>

Cool...the problems I was running into make total sense now!

>That being said, here's a simple sort by value sort:
>
>    sub bv_sort(\%) {
>	my $hr = shift;
>	return scalar keys %$hr unless wantarray();
>	return sort { $hr->{$a} <=> $hr->{$b} } keys %$hr;
>    } 
>
>    @ordered_keys = bv_sort(%random_hash);
>
>Personally, I usually just use 
>
>    @ordered_keys = sort { $hash{$a} <=> $hash{$b} } keys %hash;
>

Yeah...that's what I do, but I was attempting to make my friend throw
up by programming in perl in the style of scheme..I was more
interested in trying to find out why things work the way they do
rather than coming up with a new way of sorting hashes that I would
use day-to-day.

>Well, usually.  Othertimes I do a fancy btree binding out of DB_File
>to an in-core hash.

 ....and I was just beginning to feel that I was getting a grip on perl
programming.  ;)


Thanks Tom...you really helped me "see the Camel" on this one, so to
speak. 




				       -c


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

Date: Wed, 17 Dec 1997 06:11:09 -0600
From: Matthew Forder <mjforder@hotmail.com>
Subject: Cmd-Line perl via rsh
Message-Id: <882359769.1803223041@dejanews.com>

OK. I'm trying to execute the following command-line perl script via the
rsh command, with no success:

rsh hostname /usr/local/bin/perl -p -i.old -e '$_ !~
/^[^:]+:(\*{2,})\D+\1:/ && $_ =~
s/^username:[^:]+:/username:cryptedpasswd:/ /testdir/shadow

If executed as above, the error is returned:
ksh: syntax error at line 1 : `(' unexpected

If I execute this cmd-line..: rsh hostname "/usr/local/bin/perl -p -i.old
-e '$_ !~ /^[^:]+:(\*{2,})\D+\1:/ && $_ =~
s/^username:[^:]+:/username:cryptedpasswd:/ /testdir/shadow"

 ...the perl interpreter on hostname gives this error:
Bare word found where operator expected at -e line 1, near "/testdir"
        (Missing operator before testdir?)
syntax error at -e line 1, near "/testdir"
Bare word found where operator expected at -e line 1, near "/testdir"
        (Missing operator before testdir?)
Execution of -e aborted due to compilation errors.

Now I know that if I execute the cmd-line without 'rsh hostname' (i.e.
locally) the perl script works.

Can anyone please help?

In case you're wondering. Yes, all of the rsh permissions are set
correctly and yes, all of the file locations are correct.

Why am I doing this? I am trying to write a perl script to change a
users' password and then synchronise the new password on several
different machines. Eventually, the rsh command above will be called via
the system() command from with this perl script. I know that I should
probably use Penguin to do this, but due to circumstances way, way beyond
my control, I can't.

Thanx in advance,

Matt Forder <mjforder@hotmail.com> ----------------- "My doctor says I
have a natural deficiency in moral fibre, and a malformed public duty
gland, and I am therefore excused from saving universes."

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Wed, 17 Dec 1997 14:19:36 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Cmd-Line perl via rsh
Message-Id: <adelton.882368376@aisa.fi.muni.cz>

Matthew Forder <mjforder@hotmail.com> writes:

> OK. I'm trying to execute the following command-line perl script via the
> rsh command, with no success:
> 
> rsh hostname /usr/local/bin/perl -p -i.old -e '$_ !~
> /^[^:]+:(\*{2,})\D+\1:/ && $_ =~
> s/^username:[^:]+:/username:cryptedpasswd:/ /testdir/shadow
> 
> If executed as above, the error is returned:
> ksh: syntax error at line 1 : `(' unexpected
> 
> If I execute this cmd-line..: rsh hostname "/usr/local/bin/perl -p -i.old
> -e '$_ !~ /^[^:]+:(\*{2,})\D+\1:/ && $_ =~
> s/^username:[^:]+:/username:cryptedpasswd:/ /testdir/shadow"

I might be missing something, but where have you got the second
apostrophe (') to end up the -e command?

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 17 Dec 1997 16:55:21 GMT
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: compacting array (Figured it out)
Message-Id: <slrn69g037.gr.sitaram@ltusitaram.diac.com>

On Tue, 16 Dec 1997 09:39:24 -0700, NerveGas <NerveGas@nospam.com> wrote:
>OK, the original question was whether it was possible to compact
>null entries from an array without creating a secondary array.  Several
[snip]
>And you can tell I'm used to C.  : )  Here it is:
>
>$last_good=0;
>for ($loop=0;$loop<@array;$loop++){
>	if ($array[$loop]){
>		$array[$last_good]=$array[$loop];
>		undef($array[$loop]) if ($loop!=$last_good);
>		$last_good++;
>		}
>	}

What will the value of scalar(@array) be at the end of this?  I believe an
array is allowed to have undef entries - since it can have undef entries in
the middle, I dont see why not at the end.  So to actually shorten it (which
is part of what I understand by "compacting") you'd have to set it at the end:

    $#array = $last_good;

(will check it out when I have time if noone posts an authoritative answer)


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

Date: Tue, 16 Dec 1997 22:40:02 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: CR/LF Text-File
Message-Id: <23l776.q84.ln@localhost>

John Moreno (phenix@interpath.com) wrote:
: Tad McClellan <tadmc@metronet.com> wrote:

: > Remove xx (xxTony.Curtis@vcpc.univie.ac.at) wrote:
: > : Re: CR/LF Text-File, Tobias
: > : <udta@rzstud1.rz.uni-karlsruhe.de> said:
: > 
: > : Tobias> But the perl/skript runs on a LinuX-System.  How can
: > : Tobias> i read strings from a text-file with cr/lf at the
: > : Tobias> end of each line on a LinuX-Plattform ???
: > 
: > : Do this to the input line
: > 
: > :     s/\r$//;
: > 
: > : That will remove the CR (\r) if there's one at the end.
: > 
: > 
: > Or, better yet, when transfering the files, use FTP in ASCII mode and
: > it will convert the line endings for you.

: Why not

: $/="\r\n";  #or whatever the hex values of \r\n is


Because I didn't read the question very carefully, that's why not ;-)

That will work for data.


But I don't want to exercise my feeble grey matter each time I
transfer a file.

Now is this a script file or a text data file?
Am I going from Unix to DOS or from DOS to Unix?

If I just use ASCII mode, I don't have to worry about any of that.

So I just use ASCII mode  ;-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 17 Dec 1997 09:21:14 -0600
From: markus.rietzler@rzf.nrw.de
Subject: error when using OPEN(FILE...) under ms iis 2.0
Message-Id: <882371702.2129920012@dejanews.com>

hi,

the whole day through i tried to solve a "little" problem.

i am using perl under ms ii 2.0 on windows nt server 4.0.

the perl script is used to search a simple ascii-file as a
telephone-book-application. my problem is now: since a few days the
script crashes with an error message (something like that, tried to
translate the german error message, don't know what it is under the
english software version).

CGI-ERROR
the cgi-application doesn't write the complete http-header

when i set comments before the lines in which the ascii-file is opened,
then the script returns a complete html-page as results (without the
found telephone-book-entries of course). when i use open (FILE, "<$file")
 ..... close (FILE) then the script crashes.

tried nearly everything. the access rights on the files and directories
should be ok (iuser_xxx has the right to read RX).

is there anybody with an idea?

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Wed, 17 Dec 1997 15:01:10 GMT
From: keith_willis.junk@non-hp-unitedkingdom-om1.om.hp.com (Keith Willis)
Subject: Re: failed to close pipe into sendmail
Message-Id: <34a3e6eb.619640075@elf.bri.hp.com>

On Fri, 12 Dec 1997 18:13:51 -0800, Tom Phoenix
<rootbeer@teleport.com> wrote:

>On Fri, 12 Dec 1997, Ian Kallen wrote:
>
>> When I set $SIG{CHLD} = 'IGNORE'; or just leave it unset, the zombies
>> accumulate (watching 'top') like crazy but the program speeds right along
>> doing what I want it to do: write out messages in deferred mode to the
>> queue directory.
>
>Yes, that's what zombies do. :-) What you should probably do is use
>waitpid() to wait for them individually. 

Pardon?  I have found that if one _specifically_ sets SIGCHLD to
SIG_IGN, it does _not_ generate zombies.  This is contrast to the
SIG_DFL semantics which are to ignore the signal and to generate
zombies.

You can achieve the same thing by setting the SA_NOCLDWAIT sigaction
flag.
----------------------------------------------------------------------
The above message reflects my own views, not those of Hewlett Packard.
When emailing me, please note that there is no '.junk' in my address.


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

Date: 17 Dec 1997 14:48:23 GMT
From: "Phil R Lawrence" <prl2@lehigh.edu>
Subject: flow control
Message-Id: <01bd0afa$d453b7c0$3e03b480@mm>

I had a subroutine that checked a user's name and password for Oracle login
before:
		$dbh = DBI->connect("dbi:Oracle:$database", $uname, $upass)
			or die $DBI::errstr;
ever happened.

But the code was ugly and I thought, why not just have something like:
		$dbh = DBI->connect("dbi:Oracle:$database", $uname, $upass)
			or [...  ask the user if they want to try again if the Oracle error says

				name and password were the problem  ...]


I came up with the following, but can't get it to work right, no matter how
I push it around.  Even tried an anonymous sub (my first attempt at that)
but couldn't get that to work either.
Current try:

until (defined (my $dbh)) {
	$dbh = DBI->connect("dbi:Oracle:sa71", $uname, $upass)
		or {
			if ($DBI::errstr =~ /^ORA-1017x?/) {
				my $x = "";
				while ($x !~ /^(Y|N)/i) {
					print "Oracle login failed.  Would you like to try again?  (Y or N):
";
					chomp($x = <STDIN>);
				}
				if ($x =~ /^Y/i) {
					print "Please enter Banner username: ";
					chomp($uname = <STDIN>);
					print "\nPlease enter Banner password: ";
					ReadMode(2);  # console echo off
					chomp($upass = <STDIN>);
					ReadMode(0);  # restore original console settings
				} else {
					&exit;
				}
			} else {
				die $DBI::errstr;
			}
		}
}

Any suggestions?

-- 
Phil R Lawrence
Systems and Networking Development Services
Programmer/Analyst
prl2@lehigh.edu


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

Date: 17 Dec 1997 13:34:18 -0500
From: Dave Sill <dsill@sws5.ctd.ornl.gov>
Subject: Re: Framework for building custom HTTP servers?
Message-Id: <wx0lnxjkedx.fsf@sws5.ctd.ornl.gov>

Gisle Aas <aas@sn.no> writes:

> The HTTP::Daemon class that comes with libwww-perl should be a good
> starting point.

Thanks, that's just what I was looking for.

-- 
Dave Sill <dsill@sws5.ctd.ornl.gov>        <URL:http://web.infoave.net/~dsill>
Lockheed Martin Energy Research   Oak Ridge National Lab   Workstation Support
Take the qmail Challenge. See <URL:http://web.infoave.net/~dsill/qmail.html>


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

Date: Wed, 17 Dec 1997 14:39:21 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Framework for building custom HTTP servers?
Message-Id: <678o5h$ut$1@cyprus.atlantic.net>

According to Dave Sill <dsill@sws5.ctd.ornl.gov>:
>Is there a module or recipe for creating small special-purpose HTTP
>servers in perl?

Yes:  In LWP (libwww-perl) is HTTP::Daemon.  I've used it, it's great.
-- 
Chip Salzenberg               - a.k.a. -               <chip@pobox.com>
|| Perl Training from Stonehenge Consulting Services: (503) 777-0095 ||
         "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: Wed, 17 Dec 1997 13:13:21 +0200
From: Keren Westreich <kerenw@amdocs.com>
To: David Leach <David.Leach@dpie.gov.au>
Subject: Re: getting the pid from a system call
Message-Id: <3497B3D1.C0C60646@amdocs.com>

Hi David!

The best way to run a script in background and get its pid
is by using fork & exec:
  if ($pid = fork)
  {
	your program code...
  }
  else if ($pid == 0)
  {
     	exec scriptName
  }
  else
  {
     	error
  }

The child will run your script in background with the same pid you have
in $pid.


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

Date: Wed, 17 Dec 1997 14:57:04 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: help with hash error
Message-Id: <ELC9J4.2vu@world.std.com>

Nowick Gray <nowick@awinc.com> writes:
>I have a strange problem appearing with a cgi script I've used without
>problems at my website...suddenly the form response in the browser
>window gives the following error message:
>"Odd number of elements in hash list at /home/cougarww/cgi-bin/swift.cgi
>line 110..."

If you're editor doesn't allow you to jump to a particular line
number, (most decent programmers editors should) and you don't have a
program that will print out the source with each line preceded by line
numbers (and can't come up with one in perl, like 
 "perl -pe '$_ = "$.: $_"') then you could use the debugger to set a
breakpoint on line 110.

perl -d swift.cgi
b 110
c

The error message comes when you assign a list to a hash. When you do
this, perl takes pairs of elements and creates a key and a value for
each pair.

%hash = ('a', 1, 'b', 2, 'c',3);
foreach $key( keys %hash) {
  print "$key $hash{$key}\n";
}

If your hash has an odd number of elements, perl has no corresponding
value for a key, and complains.

%hash = ('a', 1, 'b', 2, 'c');
foreach $key( keys %hash) {
  print "$key $hash{$key}\n";
}
-- 
Andrew Langmead


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

Date: Wed, 17 Dec 1997 14:34:34 GMT
From: Craig Freter <freter@heorotsi.com>
To: gregr@ee.uwa.edu.au
Subject: Re: HELP! How to use records in Perl?
Message-Id: <3497E313.3ED2@heorotsi.com>

> Hi. I'm having some trouble at the moment trying to emulate a Pascal record
> structure in Perl. What I want is something like this:
> 
> machine_record {
>   hostname,
>   IP,
>   group,
>   traffic,
>   cost
> }

You can use a hash reference to create a Pascal like record in Perl.

$hash_ref = {key => 'value'}; will create an anonymous hash reference,
and store it in scalar variable $hash_ref.  The $hash_ref reference may
now be used as a value in a hash, where $record{new_key} = $hash_ref. 
You can now access the original value using $value =
$record{new_key}{key};

I've included a sample program below.  Hope this helps.

------- sample code ------

#!/usr/local/bin/perl -w

$machine{beavis} = mk_machine("beavis.mtv.com", "190.240.22.11");
$machine{butthead} = mk_machine("butthead.mtv.com", "190.240.22.12");

print "Beavis's full hostname is: $machine{beavis}{hostname}\n";
print "Butt-Head's IP address is: $machine{butthead}{ip}\n";

#--------------------------------------------------------
# Construct 'machine' record
#--------------------------------------------------------
sub mk_machine {

    my ($hostname, $ip) = @_;

    # construct anonymous hash reference
    my $hash_ref = {
        hostname => $hostname,
        ip       => $ip,
    };

    # return hash reference
    $hash_ref;
}

-- 
Craig Freter    <freter@freter.com>   <http://www.freter.com>
PGP fingerprint 61 A5 E2 51 F5 AC 9D 79 DD 15 56 90 F2 0A 97 25
Heorot Systems  <http://www.heorotsi.com>


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

Date: Wed, 17 Dec 1997 12:04:58 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: How get which day is in the week?
Message-Id: <comdog-ya02408000R1712971204580001@news.panix.com>

In article <678ui0$3o3@scesie10.sie.siemens.at>, "Fejes Peter" <peter.fejes@sysdata.siemens.at> wrote:

>I have tree parameter: year, month and day, I want to know how can I get
>which  day is in the week (Sun, Mon, ...)?

all the days are in the week...

however, the nifty Date modules [1] on CPAN may help you along.

good luck! :)

"hope that helps!" - TP

[1]
Comprehensive Perl Archive Network
find one near or far from you at
<URL:http://www.perl.com>

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Every time a bell rings, another programmer buys Learning Perl.


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

Date: Wed, 17 Dec 1997 18:56:39 GMT
From: FHeasley@chemistry.com (Frank)
Subject: Re: How to get everything in between <pre>....</pre> tags in html
Message-Id: <349e2044.10620943@news.halcyon.com>

On 16 Dec 1997 15:16:24 GMT, mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:

>In article <hl0176.cs.ln@localhost>, Tad McClellan <tadmc@metronet.com> wrote:
>>That is an inefficient way to get an entire file into a string.
>>
>>I would stick with the conventional idiom:
>>
>>undef $/;
>>$lines = <FILENAME>;  # slurp
>
>Or better, to avoid wrecking the input in the rest of your program:
>
>   { local $/; $lines = <FILENAME> };
>
>

Why not:

while (<FILENAME>){
$lines .= "$_";
}

?

Frank
Frank



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

Date: Wed, 17 Dec 1997 19:27:26 GMT
From: spectd@horus.sara.nl (Neil Burnett)
Subject: Re: How to get everything in between <pre>....</pre> tags in html
Message-Id: <34982724.33275076@news.eunet.be>

On Wed, 17 Dec 1997 20:19:57 +1100, Gary Ashton-Jones
<gary@ashton-jones.com.au> wrotz:

>Michael Budash wrote:
>
>> In article <343E8927.26E1@nt.com>, Daniel Lortie <dlortie@nt.com>
>> wrote:
>> >>
>> >> I have an HTML file that I read from the internet, but I want
>> >> to parse the file I receive to only keep the text between the
>> >> <pre> and </pre> tags. Is there a quick way to do this?
>> >>
>>
>> If you've only got one such occuring pair of <pre>'s, this should do
>> it:
>>
>>  open (FILENAME) or die("oops!");  # open the file (duh!)
>>  @lines = <FILENAME>;  # get all the records at once
>>  close (FILENAME);  # close the file
>>  $lines = join ('', @lines);  # make one big scalar
>>  $lines = lc($lines);  # make it lower case
>>  $tokeep = $1 if ($lines =~/<pre>(.*)<\/pre>/);  # find the pair and
>> only
>> save what's between 'em
>>
>> You get to keep any newlines...
>>
>> If there's more than one pair of <pre>'s, it' be harder, considering
>> the
>> possibilites of things like:
>>
>>   <pre>Here's some pre-text
>>   and some more.</pre><hr><pre>Here's some more pre-text without
>> starting
>> a new line.
>>   Darn! That makes it harder...</pre>
>>
>
> Use a 'greedy search' qualifier to find the first of multiple
>occurences e.g.
>
> $tokeep = $1 if ($lines =~/<pre>(.*?)<\/pre>/);  # find the pair and
>only
>
>(Note the question mark (?). It causes the RE engine to return the
>shortest match.)
>
>Or put the pattern match inside a loop to process all the occurrences
>e.g.:
>
>while ($lines =~ s/<pre>(.*?)<\/pre>//) { #removes one occurrence each
>pass through the loop
>    print $1; #or whatever you want to do
>}
>
You could also try:

@_ = $lines =~ /<pre>.*?<\/pre>/sig;
which should give you an array of the pre stuff.

Neil


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

Date: Wed, 17 Dec 1997 15:14:00 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: how to send entire script code to STDOUT if STDIN eq "help"
Message-Id: <ELCABC.DpL@world.std.com>

bart.mediamind@tornado.be (Bart Lateur) writes:

>"E. Brian Depenbrock" <ebd@sunline.net> wrote:

>>I have a perl script I wrote and used perl2exe to convert it to an
>>executable.  I did this because the boneheads I wrote it for are nosey and
>>like to look at stuff, then they break it.
>>However, I want them to be able to see the code so someone else can modify
>>it later if need be.

>How about his: give them both the script AND the EXE file.

And calculate a checksum,CRC,MD5 or something on both before you give
it to them.

If they call with a problem, and the value for the current version of
the script and your version don't match, tell them you will first have
to charge them your regular hourly rate to investigate and test their
changes.


-- 
Andrew Langmead


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

Date: Wed, 17 Dec 1997 10:56:51 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: how to send entire script code to STDOUT if STDIN eq "help"
Message-Id: <349a9afb.4961155@news.tornado.be>

"E. Brian Depenbrock" <ebd@sunline.net> wrote:

>I have a perl script I wrote and used perl2exe to convert it to an
>executable.  I did this because the boneheads I wrote it for are nosey and
>like to look at stuff, then they break it.
>However, I want them to be able to see the code so someone else can modify
>it later if need be.

How about his: give them both the script AND the EXE file.

	Bart.


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

Date: Wed, 17 Dec 1997 11:51:07 -0500
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: JPL & PERL 5.004_04 under IRIX
Message-Id: <349802FB.794B@bell-labs.com>

Greetings.

I need to use JPL and am running IRIX (we have machines running
6.2,6.3 & 6.4).  I've tried to build PERL 5.004_04 on 6.2 and
6.3 using both the SGI make and cc and GNU make and cc and have
been unsuccessful in creating a version with a dynamic libperl.so
and the system malloc (I did compile a static version with the
PERL malloc successfully).  I have discussed this problem somewhat
with others, and have not yet figured out what needs to be done
to make the compilation work properly.

If you've done this, please let me know what you did to make it
compile the dynamic libperl.so properly.  I'd especially like
to hear from anyone who actually has used JPL w/RMI under IRIX
both about the PERL compilation and about JPL and RMI in general.
What version of the SGI Java does it work with, and are there any
snags I'll need to keep an eye out for?  (Are there any snags in
particular to RMI under IRIX in general that I should try to 
avoid?) 

Thanks.

LL+P,
Stephan


-- 
  
                    "Do computers think?"
---------------------------------------------------------------
Stephan Vladimir Bugaj                      bugaj@bell-labs.com
Member of Technical Staff                        (908) 949-3875
Multimedia Communication Research Dept.     Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies   www.multimedia.bell-labs.com
PGPkey from http://www.pgp.net/wwwkeys.html or other keyservers
Non-Lucent website:     http://www.cthulhu-dynamics.com/stephan  
---------------------------------------------------------------
    STANDARD DISCLAIMER:My opinions are NOT those of LUCENT
---------------------------------------------------------------
           "Do submarines swim?" - E.W. Dijkstra


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

Date: Wed, 17 Dec 1997 14:24:15 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: LWP for Windows
Message-Id: <678n98$r3$1@cyprus.atlantic.net>

According to Yuksel Aslandogan <aslan@dbis.eecs.uic.edu>:
>Is the LWP module available for Win95 or NT?

To my knowledge, the standard LWP (libwww-perl) works fine under NoWin.
-- 
Chip Salzenberg               - a.k.a. -               <chip@pobox.com>
|| Perl Training from Stonehenge Consulting Services: (503) 777-0095 ||
         "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: 17 Dec 1997 17:25:58 GMT
From: tony@crux.blackstar.co.uk (Tony Bowden)
Subject: Re: NEED:  Fast, Fast string trim()
Message-Id: <882379594.841343@sparc.tibus.net>

Re: removing 'unwanted' space:

Summary of options to date:

1) $_ = join(" ", /\S+/g);
2) $_ = join(" ", /\S+(?: \S+)*/g); #optimized for single spaces between words
3) $_ = join(" ", split);
4) $_ = " $_ "; tr/ \n\r\t/ /s; substr($_,0,1) = substr($_,-1,1) = "";

For short strings:
  Benchmark: timing 50000 iterations of Exp1, Exp2, Exp3, Exp4...
      Exp1:  2 secs ( 2.23 usr  0.00 sys =  2.23 cpu)
      Exp2:  2 secs ( 2.22 usr  0.00 sys =  2.22 cpu)
      Exp3:  0 secs ( 1.82 usr  0.00 sys =  1.82 cpu)
      Exp4:  0 secs ( 1.72 usr  0.00 sys =  1.72 cpu)

For long strings:
  Benchmark: timing 5000 iterations of Exp1, Exp2, Exp3, Exp4...
      Exp1: 12 secs (10.92 usr  0.00 sys = 10.92 cpu)
      Exp2: 11 secs (10.91 usr  0.00 sys = 10.91 cpu)
      Exp3:  9 secs ( 8.84 usr  0.00 sys =  8.84 cpu)
      Exp4:  1 secs ( 0.96 usr  0.00 sys =  0.96 cpu)

So option 4 is better by quite a long shot...

Any advance?

Tony
-- 
-----------------------------------------------------------------------------
 Tony Bowden |  tony@tmtm.com / NooNoo@teletubbies.org / http://www.tmtm.com/
 Belfast, NI |     It's hard to taste the wine when you're drunk on the tears
-----------------------------------------------------------------------------


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 1491
**************************************

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