[11220] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4820 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 3 21:07:30 1999

Date: Wed, 3 Feb 99 18:00:22 -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, 3 Feb 1999     Volume: 8 Number: 4820

Today's topics:
    Re: Are sub-second timers possible in Perl? <emschwar@mail.uccs.edu>
    Re: Array of Dates Prior to Today (Larry Rosler)
    Re: Array of Dates Prior to Today (M.J.T. Guy)
    Re: Array of Dates Prior to Today <uri@ibnets.com>
    Re: Catching undefined symbols in subs (Martien Verbruggen)
    Re: Catching undefined symbols in subs (Bill Moseley)
    Re: Comments in Perl code beable@my-dejanews.com
        free PERL <3dsmax@home.com>
    Re: Help on making a Database using DB_File (Martien Verbruggen)
    Re: how to search for/replace name with HTML name/URL ? <emschwar@mail.uccs.edu>
    Re: HTML::TokeParser doesn't recognize Doctype (?) (Abigail)
    Re: Is perl a freeware? <revjack@radix.net>
    Re: Is perl a freeware? <palincss@his.com>
    Re: Is perl a freeware? <uri@ibnets.com>
    Re: Is perl a freeware? <kprice@cardinal.co.nz>
        Monitoring a directory for FTP <tchurch@gmu.edu>
    Re: newbie having trouble with concatination (Steve Linberg)
    Re: newbie having trouble with concatination (Tad McClellan)
    Re: Numeric Value (Tad McClellan)
    Re: Outsourcing FORMAT directives <palincss@his.com>
        passing hash references across modules mbjones@my-dejanews.com
    Re: passing hash references across modules (Martien Verbruggen)
    Re: Searching for char in a string (Martien Verbruggen)
    Re: Simple Perl Script (Tad McClellan)
        Sorting with Matts simple search script? <bencas@bigfoot.com>
    Re: Sorting with Matts simple search script? <ludlow@us.ibm.com>
    Re: Sorting with Matts simple search script? <ludlow@us.ibm.com>
    Re: Sorting with Matts simple search script? <uri@ibnets.com>
    Re: Sorting with Matts simple search script? <bencas@bigfoot.com>
    Re: The best way to learn C? (Larry Rosler)
    Re: Timer <kprice@cardinal.co.nz>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 03 Feb 1999 18:27:45 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: Are sub-second timers possible in Perl?
Message-Id: <xkfn22vj6um.fsf@valdemar.col.hp.com>

Jonathan Feinberg <jdf@pobox.com> writes:
> Jeffrey Davey <Jeffrey_Davey-P93404@email.mot.com> writes:
> > I've scanned the FAQ questions, but haven't found much helpful info
>        ^^^^^^^
> > yet.
> 
> I think you mean "skimmed".
> 
> Webster's Unabridged: 

Er, you do realize that "Webster's" is a null symbol, dictionary-wise?  I 
could put out my own dictionaryfof potato-peeling terms and call it
"Webster's Unabridged"; all perfectly legal.

> scan v.t. : 3. To go over and examine point by point; to examine with
> care; to look closely at or into; to scrutinize.

I'm curious to know what "Webster's" would omit: 

2 : b : to glance from point to point of often hastily, casually, or in
        search of a particular item <scan the want ads looking for a job> 

(from the online MWCD10 at <URL:http://www.m-w.com/>).  Your definition
is 3(a) in the same listing.

I suppose dictionary flames are akin to spelling flames in that
regard. :^)

-=Eric, wondering what will be found in *this* posting. :^)


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

Date: Wed, 3 Feb 1999 16:02:22 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Array of Dates Prior to Today
Message-Id: <MPG.1122836d469002369899ff@nntp.hpl.hp.com>

In article <79afvv$8p8$1@info.uah.edu> on 3 Feb 1999 21:44:31 GMT, Greg 
Bacon <gbacon@itsc.uah.edu> says...
> In article <79aaom$u41$1@nnrp1.dejanews.com>,
> 	johnsteele@my-dejanews.com writes:
> : Can anyone suggest a reasonably fast way to generate a list of N dates
> : prior to today?
 ...
>             ($d,$m,$y) = ( localtime($now - $i * 60 * 60 * 24) )[3,4,5];
>             $y += 1900;
>             $m++;
> 
>             push @times, sprintf "%d/%02d/%02d", $y, $m, $d;
 ...

Look, Ma, no modules!!!

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


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

Date: 4 Feb 1999 01:06:37 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Array of Dates Prior to Today
Message-Id: <79arqt$fp7$1@pegasus.csx.cam.ac.uk>

In article <79afvv$8p8$1@info.uah.edu>, Greg Bacon <gbacon@cs.uah.edu> wrote:
>In article <79aaom$u41$1@nnrp1.dejanews.com>,
>	johnsteele@my-dejanews.com writes:
>: Can anyone suggest a reasonably fast way to generate a list of N dates
>: prior to today?
>
>            ($d,$m,$y) = ( localtime($now - $i * 60 * 60 * 24) )[3,4,5];

Wrong!     (Why do I have to repeat this twice a week?)

Not all days have 24 hours in them.    That will give wrong answers for
two hours each year (in most locations).


Mike Guy


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

Date: 03 Feb 1999 20:12:38 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: Array of Dates Prior to Today
Message-Id: <39k8xzdla1.fsf@ibnets.com>

>>>>> "MJTG" == M J T Guy <mjtg@cus.cam.ac.uk> writes:

  MJTG> In article <79afvv$8p8$1@info.uah.edu>, Greg Bacon <gbacon@cs.uah.edu> wrote:
  >> In article <79aaom$u41$1@nnrp1.dejanews.com>,
  >> johnsteele@my-dejanews.com writes:
  >> : Can anyone suggest a reasonably fast way to generate a list of N dates
  >> : prior to today?
  >> 
  >> ($d,$m,$y) = ( localtime($now - $i * 60 * 60 * 24) )[3,4,5];

  MJTG> Wrong!     (Why do I have to repeat this twice a week?)

  MJTG> Not all days have 24 hours in them.    That will give wrong answers for
  MJTG> two hours each year (in most locations).

in this case all you do is make the current time be say 2pm and it will
work. the 1 hour error won't propogate to make the days wrong.

mjt's objection is that is this call occurs during the DST hour of
2am it could break.

but using a date module would be more accurate in all cases.

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: Thu, 04 Feb 1999 00:05:56 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Catching undefined symbols in subs
Message-Id: <Ev5u2.66$_E3.4792@nsw.nnrp.telstra.net>

In article <MPG.11227482e8fe0f4e9896a0@nntp1.ba.best.com>,
	moseley@best.com (Bill Moseley) writes:

> But just in case, how do I get perl to tell me that 
> unknown_name() is undefined?

You can't at compile time, because a subroutine can be defined at run
time. Witness:

# perl
print STDOUT boo, "\n";
__END__
Undefined subroutine &main::boo called at - line 1.

# perl
eval {sub boo {'boo'}};
print STDOUT boo(), "\n"
__END__
boo

You can wrap the call to the subroutine in an eval, and see if that
succeeded to prevent sudden death. Or you can use the defined function
to check:

# perldoc -f defined
[snip]
You may also use C<defined()> to check whether a subroutine exists, by
saying C<defined &func> without parentheses.
[snip]

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | 
Commercial Dynamics Pty. Ltd.       | 'I hate gramaticle errors!' 'Me to!'
NSW, Australia                      | 


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

Date: Wed, 3 Feb 1999 17:41:42 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: Catching undefined symbols in subs
Message-Id: <MPG.11229ab580cabb59896a1@nntp1.ba.best.com>

In article <Ev5u2.66$_E3.4792@nsw.nnrp.telstra.net>, mgjv@comdyn.com.au 
says...
> In article <MPG.11227482e8fe0f4e9896a0@nntp1.ba.best.com>,
> 	moseley@best.com (Bill Moseley) writes:
> 
> > But just in case, how do I get perl to tell me that 
> > unknown_name() is undefined?
> 
> You can't at compile time, because a subroutine can be defined at run
> time.

So there's no way to catch typos without actually running the code?
I write a lot of code that never gets executed unless really odd things 
are happening -- like a relational data relation that isn't what I 
expect.  Whew, that's a lot of breaking and testing, just to see if I've 
made a typo in a subroutine name.


-- 
Bill Moseley mailto:moseley@best.com


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

Date: Thu, 04 Feb 1999 00:50:13 GMT
From: beable@my-dejanews.com
Subject: Re: Comments in Perl code
Message-Id: <79aqs3$bpq$1@nnrp1.dejanews.com>

In article <36B3F32F.E42C864@yahoo.com>,
  mwebster@inetarena.com wrote:
> never seen anything anywhere (meaning, nothing in the Perl Journal, three
> different O'Reilly publications, or on any of the newgroups) about this.
> Since your system's only reading the first character of the line, I don't
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Well it's not doing that of course. Remember that a file is a
big list of characters. When the perl compiler gets to a "#" which
is a comment (as opposed to a "#" which is something else!), it has
to read every character of the file up to the comment terminator,
which is the end_of_line character.

The idea that a file is a list of lines is very useful and it's
great that perl lets you think like that. But perl is written in
C. So perl is like a graceful swan, gliding across a lake. But
underneath the water, there's these little legs, paddling like
buggery. (The little legs are the C bits).

cheers
beable van polasm
--
No, Bob Hope is DEAD, DUDE.  He can't get impeached because he's DEAD,
DUDE.  I just said so a couple of messages back!  He's DEAD, DUDE!  I have a
videotape of his funeral!  There's a website and everything!  HE'S DEAD,
DUDE!!!  HELLOOOOOOOOOOOO DUDE!  EARTH TO DUDE!  HE'S DEAD, DUDE!
-- M. Otis Beard

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 04 Feb 1999 01:23:41 GMT
From: 3dsmax <3dsmax@home.com>
Subject: free PERL
Message-Id: <36A139DA.E97BD3DB@home.com>

free PERL examples and free downloads

http://come.to/gamewire/


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

Date: Thu, 04 Feb 1999 00:45:10 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help on making a Database using DB_File
Message-Id: <q46u2.85$_E3.6087@nsw.nnrp.telstra.net>

In article <79amls$6vf$1@camel25.mindspring.com>,
	"Billy Strader" <straderb@mindspring.net> writes:
> Hey everyone....
> 
> Well I am kind of new to the perl prog. stuff but I have vreated some
> interested programs.  The program I am trying to create now deals with
> making a Database.  I am using a unix based system but I couldn't find any
> Unix mailing list.... So here I go...

Unix mailing list? This is a newsgroup. There are several unix
newsgroups, many specific to a certain OS.

> Here is what I need to do I need to create a a form/site where the first
> time a tech/user goes there it looks for a cookie and then compares it to a

Cookies are not a perl thing. They're a web thing. In perl, all you
need to do CGI things is CGI.pm. A recent version of perl includes it.

> DB to see if they have been here or not.  If they haven't been here yet it
> will ask them to fill out a form asking for some basic info:

First process
	if (cookie exists)
		open database
		retrieve data by cookie_id
		store access log data stuff
		return relevant page
	else
		do the input form thingie

Other process
	read form
	store in database, checking for duplications
	set cookie
	return relevant page

> Once they fill it out it places a cookie on their system with a unquie ID

You do realise that this is a separate process, right? You know how
the web and CGI work?

> We currently have a working type of database but it is a flat database (just
> text) and it doesn't have any of the graphics working with it yet.  I would
> give you all the URL but the server does not allow any connections to it
> from outside our domain.  But if anyone can give me any help with ideas or
> just some good links on understanding how to work with the databases or
> graphics it will be greatly appricated....

To work with databases, you will first need to determine what sort of
database you want. If some file is fine, you could look at Sprite for
text files, or AnyDBM_File for something else (possibly together with
MLDBM). Of course, since you're working with different sorts of data
you'll need to manage multiple files.

A relational DB system may be a better way to go. If I were you, I'd
go to http://www.perl.com/CPAN/modules, and look through the modules
there. There are also many other modules that will help you create
graphics and stuff.

> Mindspring Technical Support

technical support? Hmmm.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | You can't have everything, where would
Commercial Dynamics Pty. Ltd.       | you put it?
NSW, Australia                      | 


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

Date: 03 Feb 1999 18:21:34 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: how to search for/replace name with HTML name/URL ?
Message-Id: <xkfpv7rj74x.fsf@valdemar.col.hp.com>

tadmc@metronet.com (Tad McClellan) writes:
> John Owens (jowens@blit.Stanford.EDU) wrote:
> : My group has a large number of web pages that have people's names on
> : them. What I would like to do is automate adding HTML references to
> : each name I find.
> : Making this more difficult is instances of "Bitdiddle, Ben" and
> : "Bitdiddle, Ben X." and "Ben X. Bitdiddle" (for example). 
> 
>    Also making it more difficult are when there is more than
>    one Ben Bitdiddle.
>    I did this same thing a few weeks ago for a Superbowl website.
> 
>    Unfortunately, it was a work for hire, so I cannot share it with you.
> 
>    So I'll just describe the approach I used. 

<snip>

In the spirit of TMTOWTDI: nother approach may be to simply log to a
separate file all cases of duplicate names, or similar names you couldn't
disambiguate.  For a Perl script that's called frequently without human
intervention, this is a Bad  Thing(tm), but for the original poster's
requirements, it might work well  (assuming ambiguity is rare).

When you're done, examine the (hopefully few) ambiguous cases, and fix
'em by hand.  It's not elegant, but I sometimes find that one-offs like
this appears to be take up more time to debug and get them working
totally automated than the few minutes it'd take to patch up a corner
case or two.

-=Eric


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

Date: 4 Feb 1999 01:18:18 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: HTML::TokeParser doesn't recognize Doctype (?)
Message-Id: <79asgq$aod$1@client2.news.psi.net>

Marc-A. Woog (mwoog@pobox.ch) wrote on MCMLXXXII September MCMXCIII in
<URL:news:36b83695.10530699@news.datacomm.ch>:
!! 
!! I've build an HTML Beautifier which seems to work quit nicely except
!! for one small problem: HTML::TokeParser does seem to recognize
!! DocTypes as comments.

And it doesn't recognize them as oranges either.

Document types are document types. They are not comments.




Abigail
-- 
perl -wlne '}for($.){print' file  # Count the number of lines.


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

Date: 4 Feb 1999 00:09:44 GMT
From: Ed Hitler <revjack@radix.net>
Subject: Re: Is perl a freeware?
Message-Id: <79aog8$6ph$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight

Martien Verbruggen explains it all:

:PS. You'll find out that perl is free. Any advice to silly questions
:on this newsgroup however is charged at a going rate of about $1 - $5
:per word, depending on context. That is why I am going on about this,
:because every word I type earns me another $5. Expect the bill soon.

Do I need a computer to run perl?

-- 
  /~\  bygone smother Oldsmobile hull straighten showplace garden Rico
 C oo  Chang dietician turban circumcise confederate anonymous riotous
 _( ^) 1 , 0 0 0 , 0 0 0   m o n k e y s   c a n ' t   b e   w r o n g
/___~\ http://3509641275/~revjack  02/03/99 19:08:34 revjack@radix.net


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

Date: Wed, 03 Feb 1999 19:30:06 -0500
From: Steve Palincsar <palincss@his.com>
Subject: Re: Is perl a freeware?
Message-Id: <36B8EA0E.268874CF@his.com>

Ed Hitler wrote:
> 
> Martien Verbruggen explains it all:
> 
> :PS. You'll find out that perl is free. Any advice to silly questions
> :on this newsgroup however is charged at a going rate of about $1 - $5
> :per word, depending on context. That is why I am going on about this,
> :because every word I type earns me another $5. Expect the bill soon.
> 
> Do I need a computer to run perl?

Well, the cover of a recent issue of The Perl Journal shows a
perl
installation on a 1930's vintage Underwood manual typewriter. 
You
may wish to check it out.


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

Date: 03 Feb 1999 19:58:38 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: Is perl a freeware?
Message-Id: <39ognbdlxc.fsf@ibnets.com>

>>>>> "SP" == Steve Palincsar <palincss@his.com> writes:

  >> Do I need a computer to run perl?

  SP> Well, the cover of a recent issue of The Perl Journal shows a perl
  SP> installation on a 1930's vintage Underwood manual typewriter.  You
  SP> may wish to check it out.

that install failed if you look at the output of configure. one of the
most clever covers so far!

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: Thu, 04 Feb 1999 14:54:43 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Is perl a freeware?
Message-Id: <36B8FDE3.7F73D182@cardinal.co.nz>

Ed Hitler wrote:
> 
> Martien Verbruggen explains it all:
> 
> :PS. You'll find out that perl is free. Any advice to silly questions
> :on this newsgroup however is charged at a going rate of about $1 - $5
> :per word, depending on context. That is why I am going on about this,
> :because every word I type earns me another $5. Expect the bill soon.
> 
> Do I need a computer to run perl?
> 

I understand there are several pe[a]rl implementations in the mollusc
family.

You could always run a full mental simulation !  8-D


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

Date: Thu, 04 Feb 1999 00:53:02 GMT
From: YosemiteSam <tchurch@gmu.edu>
Subject: Monitoring a directory for FTP
Message-Id: <79ar1b$bqg$1@nnrp1.dejanews.com>

I am monitoring a directory to watch for incoming files.  I am doing this via
a cron job.  When I find files in the directory, I am trying to see if an FTP
session is active on any of the files via a select statement, but cant get
this to work.  Does anyone have a code example using the select statement?

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 04 Feb 1999 01:08:54 GMT
From: slinberg@crocker.com (Steve Linberg)
Subject: Re: newbie having trouble with concatination
Message-Id: <slinberg-0302992008540001@cc11620-a.lwmrn1.pa.home.com>

In article <x3yemo7mipn.fsf@tigre.matrox.com>, Ala Qumsieh
<aqumsieh@matrox.com> wrote:

> No! The newline was matched by the \s* which you have in your regexp,
> but which is not in the original poster's regexp. Try removing it and
> running you little test case again. Better still, have another look at
> perldoc perlre.

Yes, I know.  I'm banishing myself from this group for two weeks as
punishment.  :)


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

Date: Wed, 3 Feb 1999 19:14:26 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie having trouble with concatination
Message-Id: <i9sa97.hj2.ln@magna.metronet.com>

Steve Linberg (slinberg@crocker.com) wrote:
: In article <3r6897.ij6.ln@magna.metronet.com>, tadmc@metronet.com (Tad
: McClellan) wrote:

: > Steve Linberg (linberg@literacy.upenn.edu) wrote:
: > : In article <36B70CF4.3AB3@ee.surrey.ac.uk>, Gavin Ian Andrew Kenny
: > : <eem3gk@ee.surrey.ac.uk> wrote:
: > 
: > : > $line =~ /\s*(\S+.*)$/; # this gets rid of tab at the start and \n
: > : > at                                      # the end


: > : Your .* matches everything to the end of the string.
: > 
: >    No, it doesn't match the newline at the end of the string,
: >    which, I believe, was the whole point   :-)

: It doesn't?


   Right.

   It doesn't.


: $line =~ s/\s*(.*?)\s*$/$1/;


   No cheating!  :-)

   That isn't the same pattern. C'mon now, play fair.

   Try it with the pattern that I was talking about (quoted above).


: Looks like it matched the newline to me. "." matches everything, right?


   No. dot matches everything except a newline.

   That is why Perl offers the s///s option to make dot
   _really_ match anything.

   \s always matches newline though, which is the part of this
   new pattern that is getting rid of the newline.


: Memo to self: reread the FAQ once a month.  Things slip out.


   Uhh. Better put 'perlre' on your reading list too.  heh, heh


------------------------------------
In particular the following metacharacters have their standard I<egrep>-ish
meanings:
 ...
    .   Match any character (except newline)
------------------------------------


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


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

Date: Wed, 3 Feb 1999 19:39:12 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Numeric Value
Message-Id: <0ota97.4n2.ln@magna.metronet.com>

Ala Qumsieh (aqumsieh@matrox.com) wrote:

: Frank de Bot <debot@xs4all.nl> writes:

: > Does anybody knows a way to check if a string is numeric or not?

: print "Is numeric.\n" if $string =~ /^[-+\d.]+$/;


---------------
#!/usr/bin/perl -w
use strict;

foreach my $string ( qw( - ... 1.2.3.4 1---3 )) {
   print "'$string' Is numeric.\n" if $string =~ /^[-+\d.]+$/;
}
---------------

'-' Is numeric.
'...' Is numeric.
'1.2.3.4' Is numeric.
'1---3' Is numeric.


That's news to me...


If you are going to give an answer again rather that refer folks
to the answers validated by hundreds of pairs of eyes in the
FAQ, your answer should at least be some approximation of correct.

:-)


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


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

Date: Wed, 03 Feb 1999 19:37:25 -0500
From: Steve Palincsar <palincss@his.com>
Subject: Re: Outsourcing FORMAT directives
Message-Id: <36B8EBC5.A9FA7AE4@his.com>

You do not have to go as far as creating a module.  You can
put any arbitrary chunk of perl code (including format
declarations)
in a file and load it at compile time with a "require" or a "do".
You do have to have the file end in a true value (customarily
a 1; as the last line in the file), and if you use "require" the
file has to be on the @INC search path, wheras with "do" you can
specify the full path to the file regardless of where it is.

Marc-A. Woog wrote:
> 
> Hi,
> 
> If I need a lot of format declarations for write() in a script or need
> the same declaration for different scripts it gets harder to manage
> them. Is there a way to keep this format stuff in a separate file and
> just reference (maybe the wrong word here) in the main script? Do I
> have to write PMs for that and use require|use then?
> 
> Thanks for any answers.
> 
> Regards,
> 
> Marc


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

Date: Wed, 03 Feb 1999 23:59:46 GMT
From: mbjones@my-dejanews.com
Subject: passing hash references across modules
Message-Id: <79ante$9bp$1@nnrp1.dejanews.com>

Is it possible to pass hash references across modules?  I want to pass
a bunch of hashes that are created in my MAIN package to a sub in
another package, but when I do and look at the dereferenced value
for the hash ref that I get in the sub, it has been "stringified" (as
is described in the docs and FAQ regarding using references as hash
keys, which is not what I am doing).

If I take the subroutine out of the module and place it
into the MAIN package, everything works fine. I give an example below
with output showing the "stringified" reference. Thanks for your help,

Matt

I'm using perl version 5.005_02 on SGI IRIX 6.2.

Here's a little example that illustrates my problem:

#!/usr/local/bin/perl
use lib qw(./TestMod );
use TestMod;

my %hash = ( 'a' => 'val-a', 'b' => 'val-b' );
my $tm = new TestMod;

&testRefPassing(\%hash);
$tm->testRefModPassing(\%hash);

sub testRefPassing {
  my $href = shift;
  print "starting testRefPassing\n";
  print "The ref value looks like: $href\n";

  my $key;
  foreach $key (keys %$href) {
    print "$key => $href->{$key}\n";
  }
  print "ending testRefPassing\n";
}

**************************************************
* BEGIN CODE FOR THE TestMod.pm module
**************************************************

package TestMod;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;
require AutoLoader;

@ISA = qw(Exporter AutoLoader);
@EXPORT = qw();
$VERSION = '0.01';

# the constructor -- just make an instance
sub new {
  my $type = {};
  bless $type;
  return $type;
}

sub testRefModPassing {
  my $href = shift;
  print "starting testRefModPassing\n";
  print "The ref value looks like: $href\n";

  my $key;
  foreach $key (keys %$href) {
    print "$key => $href->{$key}\n";
  }
  print "ending testRefModPassing\n";
}

1;

**************************************************
* OUTPUT FROM THE PROGRAM
**************************************************

starting testRefPassing
The ref value looks like: HASH(0x1002937c)
a => val-a
b => val-b
ending testRefPassing
starting testRefModPassing
The ref value looks like: TestMod=HASH(0x1006b684)
ending testRefModPassing


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 04 Feb 1999 00:55:29 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: passing hash references across modules
Message-Id: <5e6u2.86$_E3.6087@nsw.nnrp.telstra.net>

In article <79ante$9bp$1@nnrp1.dejanews.com>,
	mbjones@my-dejanews.com writes:
> Is it possible to pass hash references across modules?  I want to pass
> a bunch of hashes that are created in my MAIN package to a sub in
> another package, but when I do and look at the dereferenced value
> for the hash ref that I get in the sub, it has been "stringified" (as
> is described in the docs and FAQ regarding using references as hash
> keys, which is not what I am doing).

> &testRefPassing(\%hash);

> sub testRefPassing {
>   my $href = shift;
>   print "starting testRefPassing\n";
>   print "The ref value looks like: $href\n";

It gets stringified here, by the double quotes. It wasn't stringified
before that. But there is something else wrong:

You call the sub in your module like this, as a method:

> $tm->testRefModPassing(\%hash);

but you define it like this, as a regular sub:

> sub testRefModPassing {
>   my $href = shift;

The first argument to a method is always the blessed object or the
class it was called on. The first line should always be:

my $self = shift;

# perldoc perlobj
# perldoc perltoot

it works fine this way:

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

use strict;

package SomeMod;

# Yes, I know this is minimal. It's sufficient.
sub new { return bless {} };

sub hashReffer {
	my $self = shift;
	my $hr = shift;

	# Check to see that it is indeed a hash reference
	(ref($hr) =~ /HASH/) || die "Not a hash ref\n";

	# Print out the has elements
	foreach (keys %$hr)
	{
		print "$_:$hr->{$_}\n";
	}
}

package main;

my %H = ( aa => 'bb', cc => 'dd' );

my $s = SomeMod->new();
$s->hashReffer(\%H);

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | This matter is best disposed of from a
Commercial Dynamics Pty. Ltd.       | great height, over water.
NSW, Australia                      | 


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

Date: Thu, 04 Feb 1999 00:28:11 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Searching for char in a string
Message-Id: <vQ5u2.79$_E3.5615@nsw.nnrp.telstra.net>

In article <79alem$72a$1@nnrp1.dejanews.com>,
	lamj@softhome.net writes:
> I have been looking for the most efficient way to find if there are any a-z
> and A-Z characters in a string variable $abc but without success. Can anyone
> please tell me the best way to do such a search?

if ($abc = /[a-zA-Z]/) { }
$num = ($abc =~ tr/a-zA-Z//);

There are other ways.

You really should consider reading some documentation.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | This matter is best disposed of from a
Commercial Dynamics Pty. Ltd.       | great height, over water.
NSW, Australia                      | 


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

Date: Wed, 3 Feb 1999 17:51:28 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Simple Perl Script
Message-Id: <0ena97.2g2.ln@magna.metronet.com>

Stuart Lester (gt3511a@prism.gatech.edu) wrote:

: Does anyone happen to know how to get perl to do the following (when
: passed a filename and string):
: Search the entire file <filename> for the string.  When found the ENTIRE
: line is deleted.  Repeat for all instances of <string>.
: I am pretty sure this would only be a simple script, but i don't know
: the syntax to delete an entire line.


   perl -n -e 'print unless /string/' filename >filename.trimmed


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


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

Date: Thu, 4 Feb 1999 00:17:39 -0000
From: "el_pollo_diablo" <bencas@bigfoot.com>
Subject: Sorting with Matts simple search script?
Message-Id: <79ap18$dg4$1@news5.svr.pol.co.uk>

Hi,

I'm not much of a perl programmer but I'm trying to make matts simple search
script (from www.worldwidemart.com) sort the outputted titles
alphabetically.

The actual piece of code to display the pages is this:

foreach $key (keys %include) {
if ($include{$key} eq 'yes') {

print "<li><a href=\"$baseurl$key\">$titles{$key}</a>\n";

}

I'm pretty sure the sort command goes in here somewhere but i'm at a loss.



Perhaps one of you clever chappies could point me in the right direction.

Thanks



Ben





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

Date: Wed, 03 Feb 1999 19:04:54 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Sorting with Matts simple search script?
Message-Id: <36B8F236.AAA5F99B@us.ibm.com>

el_pollo_diablo wrote:

> I'm not much of a perl programmer but I'm trying to make matts simple search
> script (from www.worldwidemart.com) sort the outputted titles
> alphabetically.
> 
> The actual piece of code to display the pages is this:
> 
> foreach $key (keys %include) {
> if ($include{$key} eq 'yes') {
> 
> print "<li><a href=\"$baseurl$key\">$titles{$key}</a>\n";
> 
> }
> 
> I'm pretty sure the sort command goes in here somewhere but i'm at a loss.

It's probably easiest to break this up into two loops.  The first one
will make a list of keys that are to be included.  Then we'll sort that
list of keys based on the titles they correspond to.  Then in the second
loop you actually do the printing.

For example:

#!/usr/bin/perl -w
use strict;

my %title = (1 => 'BBBBBB',
             2 => 'CCCCCC',
             3 => 'AAAAAA',
             4 => 'XXXXXX',
             5 => 'DDDDDD',
             6 => 'QQQQQQ',
            );

# Note that not saying 'yes' is the same thing as saying 'no'
my %include = (1 => 'yes',
               2 => 'yes',
               3 => 'yes',
               5 => 'yes',
              );

# build list of included keys
my @includedKeys = ();           
foreach (keys %include) {
    if ($include{$_} eq 'yes') {
        push @includedKeys, $_;
    }
}

# Now you need to sort @includedKeys so that you will be
# getting data from %title in the correct (sorted) order.

my @sortedKeys = sort {$title{$a} cmp $title{$b}} @includedKeys;

# now print your titles
foreach (@sortedKeys) {
    print $title{$_}, "\n";
}

-- 
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)


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

Date: Wed, 03 Feb 1999 19:24:26 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Sorting with Matts simple search script?
Message-Id: <36B8F6CA.C8BB7FDB@us.ibm.com>

Uri Guttman wrote:
> 
> >>>>> "epd" == el pollo diablo <bencas@bigfoot.com> writes:
> 
>   epd> Hi, I'm not much of a perl programmer but I'm trying to make
>   epd> matts simple search script (from www.worldwidemart.com) sort the
>   epd> outputted titles alphabetically.
> 
>   epd> foreach $key (keys %include) {
>                      ^sort

That will sort by key value.  He wanted to sort by title.  Only by
coincidence would this work.

>   epd> Perhaps one of you clever chappies could point me in the right
>   epd> direction.
> 
> yes. go away from matt's scrapts (sic). they are not worth the bits they
> take up in storage. we get more problems in this group from his crap
> code than any other place.

No argument here.  If you really want to learn about CGI programming in
Perl, spend less time with Matt, and more time with the CGI.pm docs.

-- 
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)


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

Date: 03 Feb 1999 20:13:39 -0500
From: Uri Guttman <uri@ibnets.com>
To: "el_pollo_diablo" <bencas@bigfoot.com>
Subject: Re: Sorting with Matts simple search script?
Message-Id: <39hft3dl8c.fsf@ibnets.com>

>>>>> "epd" == el pollo diablo <bencas@bigfoot.com> writes:

  epd> Perhaps one of you clever chappies could point me in the right
  epd> direction.

yes. go away from matt's scrapts (sic). they are not worth the bits they
take up in storage. we get more problems in this group from his crap
code than any other place.

hth,

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: Thu, 4 Feb 1999 01:30:45 -0000
From: "el_pollo_diablo" <bencas@bigfoot.com>
Subject: Re: Sorting with Matts simple search script?
Message-Id: <79ata9$ji7$1@news8.svr.pol.co.uk>

Hi ! Help!
I inserted your modified code into the script and I am now receiving no
output.



sub return_html {

print "Content-type: text/html\n\n";

print "<html>\n <head>\n <title>Results of Search</title>\n </head>\n";

print "<body
background='http://www.atlantic-arc.com/watersports/images/search.jpg'>\n
<center>\n <h1>Results:</h1>\n </center>\n";

print "Below are the results of your search in no particular order:<p><hr
size=7 width=75%><p>\n";

print "<ul>\n";


# build list of included keys

my @includedKeys = ();

foreach (keys %include) {

if ($include{$_} eq 'yes') {

push @includedKeys, $_;

}

}

# Now you need to sort @includedKeys so that you will be

# getting data from %title in the correct (sorted) order.

my @sortedKeys = sort {$title{$a} cmp $title{$b}} @includedKeys;

# now print your titles

foreach (@sortedKeys) {

print $title{$_}, "\n";

}

print "</ul><br><hr size=7 width=75%><P>\n";

print "<ul>\n<li><a href=\"$search_url\">Back to Search Page</a>\n";

print "<li><a href=\"$title_url\">$title</a>\n";

print "</ul>\n";

print "<hr size=7 width=75%>\n";

print "<p align='center'><a href='http://www.atlantic-arc.com'><img
src='http://www.atlantic-arc.com/watersports/images/atlantic_small.gif'
border=0></a></p>\n";

print "</body>\n</html>\n";

}

what needs changing?

James Ludlow <ludlow@us.ibm.com> wrote in message
news:36B8F236.AAA5F99B@us.ibm.com...
>el_pollo_diablo wrote:
>
>> I'm not much of a perl programmer but I'm trying to make matts simple
search
>> script (from www.worldwidemart.com) sort the outputted titles
>> alphabetically.
>>
>> The actual piece of code to display the pages is this:
>>
>> foreach $key (keys %include) {
>> if ($include{$key} eq 'yes') {
>>
>> print "<li><a href=\"$baseurl$key\">$titles{$key}</a>\n";
>>
>> }
>>
>> I'm pretty sure the sort command goes in here somewhere but i'm at a
loss.
>
>It's probably easiest to break this up into two loops.  The first one
>will make a list of keys that are to be included.  Then we'll sort that
>list of keys based on the titles they correspond to.  Then in the second
>loop you actually do the printing.
>
>For example:
>
>#!/usr/bin/perl -w
>use strict;
>
>my %title = (1 => 'BBBBBB',
>             2 => 'CCCCCC',
>             3 => 'AAAAAA',
>             4 => 'XXXXXX',
>             5 => 'DDDDDD',
>             6 => 'QQQQQQ',
>            );
>
># Note that not saying 'yes' is the same thing as saying 'no'
>my %include = (1 => 'yes',
>               2 => 'yes',
>               3 => 'yes',
>               5 => 'yes',
>              );
>
># build list of included keys
>my @includedKeys = ();
>foreach (keys %include) {
>    if ($include{$_} eq 'yes') {
>        push @includedKeys, $_;
>    }
>}
>
># Now you need to sort @includedKeys so that you will be
># getting data from %title in the correct (sorted) order.
>
>my @sortedKeys = sort {$title{$a} cmp $title{$b}} @includedKeys;
>
># now print your titles
>foreach (@sortedKeys) {
>    print $title{$_}, "\n";
>}
>
>--
>James Ludlow (ludlow@us.ibm.com)
>(Any opinions expressed are my own, not necessarily those of IBM)




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

Date: Wed, 3 Feb 1999 15:58:29 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: The best way to learn C?
Message-Id: <MPG.11228282f31e0eb79899fe@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36B8D569.14C64624@crucibledesign.com> on Wed, 03 Feb 1999 
23:02:01 +0000, Aidan Rogers <aidan@crucibledesign.com> says...
 ... 
> I am a Perl programmer, and it is the only language I really know (and
> love). However, I want to learn how to program in C (and eventually
> C++), for
> the usual job related reasons. Can anyone who has taught themselves
> recommend
> a way to go about it? Is there a good book on the subject (like the
> Camel book
> is to Perl)? The reason I'm asking on the ng is because I want the
> answer from a
> fellow Perl programmer, someone who knows the Perl frame of mind, and so
> can recommend a better way than someone who only programs in C.

I learned C first, and had a hand in writing some of the books.  
However, I think I can advise you from a Perl perspective.

If you are comfortable with the Camel book, you will have no trouble 
whatsoever with the corresponding C 'Bible', "The C Programming 
Language" by Kernighan and Ritchie, second edition.

Depending on your interests, there are many other fine books, such as 
"Algorithms in C" by Sedgewick, any book by Plauger (especially about 
ANSI/ISO C), and most books by Plum.

Prepare for some frustration, because of the need for explicit memory 
management in many applications, the primitive string-handling 
capabilities, and the lack of regular expressions.  You will have to 
write and debug many more lines of code to achieve the same purposes, 
but it will often run much faster, if that is important.

Enjoy!

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


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

Date: Thu, 04 Feb 1999 13:05:02 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Timer
Message-Id: <36B8E42E.370D208E@cardinal.co.nz>

dkelly@emhain.wit.ie wrote:
> 
> Hi,
> 
> I am working on a Perl script that is running on a Unix system.  I want to
> have my script run automatically at a fixed time each day.
> 
> I am not allowed to run it by use of the CRONTAB or BATCH facilities on the
> Unix system.  I need it to run through the use of Perl code.
> 
> Any help would be appreciated.
> 
> Kelly
> 
cron really is the best thing for what you want to do.
The alternative is to put a loop around your script and nohup
<scriptname> &.
You will then have to check periodically yourself to see if it is still
running.  If the unix host is rebooted it will be lost and you will have
to nohup it again.

man nohup

HTH

Kelvin


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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 4820
**************************************

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