[18956] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1151 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 18 06:05:56 2001

Date: Mon, 18 Jun 2001 03:05:08 -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: <992858708-v10-i1151@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 18 Jun 2001     Volume: 10 Number: 1151

Today's topics:
        Add LDAP entry <henryNOSPAM@larioja.org>
    Re: Another possible need for a pattern match <bol@adv.magwien.gv.at>
    Re: Best way for batch renaming specific files <john.imrie@pa.press.net>
    Re: compiling with perl <der.prinz@gmx.net>
        exclusive access to database <eng80956@nus.edu.sg>
    Re: exclusive access to database <pne-news-20010618@newton.digitalspace.net>
    Re: Filehandles and close. (Anno Siegel)
    Re: Filehandles and close. <goldbb2@earthlink.net>
    Re: finding a file in a directory?? <pne-news-20010618@newton.digitalspace.net>
    Re: I can't belive I'm asking this here... <pne-news-20010618@newton.digitalspace.net>
    Re: Install Perl on HP <h.m.brand@hccnet.nl>
    Re: Install Perl on HP <pne-news-20010618@newton.digitalspace.net>
    Re: Newbie Post : Flushing output for long scripts <bholness@nortelnetworks.com>
        open a http://www.domein.com.file <question_1@hetnet.nl>
    Re: open a http://www.domein.com.file <der.prinz@gmx.net>
    Re: open a http://www.domein.com.file <bart.lateur@skynet.be>
    Re: Perl2Exe Decompiler? <Deneb.Pettersson@lmf.ericsson.se>
    Re: Printing filenames that are in a directory <john.imrie@pa.press.net>
        Problem with redirect (with IE and not with Netscape) <dvdw@plan.be>
    Re: Sending Attachments Via Sendmail <Jenda@Krynicky.cz>
    Re: setting @INC at perl compile time <john.imrie@pa.press.net>
    Re: Sorting hash <goldbb2@earthlink.net>
    Re: Sorting hash <krahnj@acm.org>
    Re: supressing error messages in NT <Jenda@Krynicky.cz>
    Re: What is the ideal way to parse? <Jenda@Krynicky.cz>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 18 Jun 2001 10:30:38 +0200
From: Enrique =?iso-8859-1?Q?Ochagav=EDa?= <henryNOSPAM@larioja.org>
Subject: Add LDAP entry
Message-Id: <3B2DBC2E.A12DC672@larioja.org>

How to add a ldap entry?


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

Date: Mon, 18 Jun 2001 09:38:20 +0200
From: Ferry Bolhar <bol@adv.magwien.gv.at>
Subject: Re: Another possible need for a pattern match
Message-Id: <992849891.764478@mozart.adv.magwien.gv.at>

Logan Shaw wrote:
> 
> In article <9gbnuj$e3e$1@plutonium.btinternet.com>,
> Leo Hemmings <leapius@hotmail.com> wrote:
> >I need to substitute a string with the equivalent number of stars "*".
> >
> >E.g:
> >
> >hello = *****
> >love perl = *********
> 
> $string =~ s/./\*/g;

or shorter:

$string =~ /./*/g;

The '\' can be omitted here because the '*' must be escaped in the regex
only, not in the replacement string.

> By the way, I suggest reading/learning about regular expressions.

I suggest too... ;-)

Greetings, Ferry

-- 
Ing. Ferry Bolhar-Nordenkampf
Municipality of Vienna
Municipality Department 14
A-1010 Vienna
E-mail: bol@adv.magwien.gv.at

"Wenn hier einer schuld ist, dann immer nur der Computer."


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

Date: Mon, 18 Jun 2001 10:46:15 +0100
From: "John Imrie" <john.imrie@pa.press.net>
Subject: Re: Best way for batch renaming specific files
Message-Id: <a6kX6.1443$h45.8794@news.uk.colt.net>


Michael Segulja <michael.segulja@kingwoodcable.net> wrote in message
news:3b2a407c$1_3@newsfeeds...
> I have some files name filename.0001, filename.0002....filename.0450, etc.
> I want to rename these files to filename.0001.tif,
> filename.0002.tif....filename.0450.tif, but I'm not sure how.  I'm sure
Perl
> is the best solution for this since I'm running Linux, but I'm not a Perl
> programmer.  Is this something that is easy enough to figure out with a
> decent tutorial?  I'd like to learn how to do it, but I haven't found
> anything on the Internet that is specific to something like this.
>
> Can someobody give me a head start or some ideas on where to look?
>
> Thank you very much,
>
> Michael

If you want all the files in the directory to be modified then this should
work

perl -ni.tif -e 'unlink'

Why is left as an exercise to the reader :-)




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

Date: Mon, 18 Jun 2001 09:58:18 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: compiling with perl
Message-Id: <3b2db432$1@e-post.inode.at>

Aman Patel <patelnavin@icenet.net> wrote:

> any information on creating self executable binaries out of the source code?
> i know all about perl2exe, but i would like to know if this could run as CGI
> application? is it possible to encrypt the perl source code, so no one can
> see it, and there should not be any decompiler for it so that it would give
> the source ditto from the original script.

This is a FAQ.
See `perldoc -q hide`

cheers,
stefan





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

Date: Mon, 18 Jun 2001 15:43:13 +0800
From: Murlimanohar Ravi <eng80956@nus.edu.sg>
Subject: exclusive access to database
Message-Id: <191C91BDFE8ED411B84400805FBE794C12137BC4@pfs21.ex.nus.edu.sg>
Keywords: "exclusive access to database"


Hi all,
Thanks for reading this.
I wrote a Perl script running on WinNT4 that accesses an MSAccess db by
passing it SQL commands. I've set up an ODBC data source but I'm not
sure whether or not I should enable exclusive access to the database.
When I think about it, exclusive access seems to be the way to go but I
don't know how to handle situations where more than one instance of my
CGI script tries to write to the database. My script could theoretically
be accessed by more than one user at any given moment so that's why I'm
thinking about exclusive access.
Could someone please tell me whether this is an OS-level issue? Does
WinNT take care of exclusive write-access automatically or do I have to
specifically write a lock/queue/unlock routine in my script to ensure
exclusive access? Of course I'd much prefer that NT lets only one write
operation proceed at any given moment -- less complications for me! But
if it doesn't work that way, could someone please tell me whether they
have any ideas for me?
Appreciate any and all suggestions.
Cheers,
Murli.



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

Date: Mon, 18 Jun 2001 10:16:41 +0200
From: Philip Newton <pne-news-20010618@newton.digitalspace.net>
Subject: Re: exclusive access to database
Message-Id: <v4eritcuf7vea39fmf7u480sfgtsdfrour@4ax.com>

On Mon, 18 Jun 2001 15:43:13 +0800, Murlimanohar Ravi
<eng80956@nus.edu.sg> wrote:

> I'm not sure whether or not I should enable exclusive access to the
> database.

Any database worth its salt should be able to handle concurrent access
by multiple clients just fine. (One good reason why to choose a database
over flat files, where you have to figure out locking by yourself.)

That being said, I don't know whether MS Access does so. Consult someone
who know about MS Access.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 18 Jun 2001 07:33:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Filehandles and close.
Message-Id: <9gkaso$9ro$1@mamenchi.zrz.TU-Berlin.DE>

According to Kiel R Stirling <taboo@comcen.com.au>:
> 
> Hi all,
> 
> My question is on filehandles.
> 
> If you open a file like so 
> 
> open F, '/etc/hosts.allow' or die $!;
> 
> and then loop through the file in a while loop 
> 
> while( <F> ) {
> 	# do something..
> }
> 
> 
> At this point is there a need to call close on the filehandle?

No.

> Doesn't while( <F> ) imply while the filehandle is open? 

No.

> So a call to close is really pointless, wasteful!

No.

> Any Idea's??

There is a difference between an eof() condition on a filehandle
and closing it.  Read about it in perldoc (eof and close) as well
as in the documentation that came with your system.

Anno




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

Date: Mon, 18 Jun 2001 03:48:54 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Filehandles and close.
Message-Id: <3B2DB266.EF30EFC0@earthlink.net>

Kiel R Stirling wrote:
> 
> Hi all,
> 
> My question is on filehandles.
> 
> If you open a file like so
> 
> open F, '/etc/hosts.allow' or die $!;
> 
> and then loop through the file in a while loop
> 
> while( <F> ) {
>         # do something..
> }
> 
> At this point is there a need to call close on the filehandle?
> 
> Doesn't while( <F> ) imply while the filehandle is open?
> So a call to close is really pointless, wasteful!

The while( <F> ) means, while( the filehandle has not reached EOF ).  It
does not mean, while( the filehandle is open ).  After the while loop
finishes, F is at the end of the file, but it is still open; you can use
seek or rewind to put it back at the beginning.

If you want a magical close, then something like this is the way to do
it:
{
	open my $f, '/etc/hosts.allow' or die $!;
	while( <$f> ) {
		#
	}
}	# when the lexical, $f, goes out of scope, it gets closed.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Mon, 18 Jun 2001 10:33:40 +0200
From: Philip Newton <pne-news-20010618@newton.digitalspace.net>
Subject: Re: finding a file in a directory??
Message-Id: <cberit05a4am8k6h24m05cvaecgj87iunp@4ax.com>

On 17 Jun 2001 22:58:47 -0700, nina_samimi@yahoo.com.au (Nina) wrote:

> How can I find an specific file in a directory? Is there anyway I
> can search for a file like Unix commands "ls -tr what.*.4Jun.*" ???

The two most common methods are probably glob and
opendir/readdir/closedir. glob usually sorts the filenames it returns in
alphabetical order (though if you use File::Glob, you can customise
that) and includes the directory name in the results if you passed it to
the function (e.g. glob('/foo/*.bar') might result in a list containing
'/foo/glork.bar'); readdir gives you the names of directory entries in
the order they are stored in the directory (which often looks fairly
random).

Examples of use:

    my @files = glob 'what.*.4Jun.*';

or

    opendir DIR, '.' or die "Can't opendir '.': $!";
    my @files = grep /^what\..*\.4Jun\./s, readdir DIR;
    closedir DIR or die "Can't closedir '.': $!";

(Note that grep uses regular expression syntax, which is not the same as
glob syntax. Specifically in this case, dot does not match itself and
star by itself does not match "zero or more characters".)

If you want the output sorted as with ls -tr (newest last), you'll have
to do the sorting yourself. Perhaps something like this:

    opendir DIR, '.' or die "Can't opendir '.': $!";
    my @files = map  { $_->[1] }
                sort { $a->[0] <=> $b->[0] }
                map  { [ (stat($_))[9], $_ ] }
                grep { /^what\..*\.4Jun\./s }
                readdir DIR;
    closedir DIR or die "Can't closedir '.': $!";

If you readdir a different directory than '.', you'll have to prepend
the directory name in the stat call (e.g. opendir DIR, $dir or die...
and then ...stat("$dir/$_")[9]...).

(Finally, you could also call ls explicitly, perhaps like this: my
@files = `ls -tr what.*.4Jun.*`; . But that's not very portable.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Mon, 18 Jun 2001 10:13:53 +0200
From: Philip Newton <pne-news-20010618@newton.digitalspace.net>
Subject: Re: I can't belive I'm asking this here...
Message-Id: <lodrit89l2n5uaj3e0jekk0q7vpd3lbkph@4ax.com>

[Please use a subject line that relates to the subject of your post]

On Sun, 17 Jun 2001 23:14:55 GMT, Kim C <kimmfc@mydeja.com> wrote:

> I have an embarrassingly simple question to ask:  How does one copy an
> entire directory (with sub directories if necessary)?

TMTOWTDI. One way is to use File::Find to go through the directory
structure and then use mkdir and File::Copy. Another would be to shell
out to a utility program for that purpose (e.g. 'system "cp -R foo bar"'
or whatever).

> the File::Copy man pages mention File::Copydir

I didn't see that mention. However, it may not be in my version of
File::Copy.

> but this does not work on my system (win2000 / ActivePerl 5.6).

Where did you find the File::Copydir that didn't work? (There appears to
be nothing on CPAN by that name.) What did you expect it to do? What did
it actually do? ("doesn't work" is rather vague.)

> I saw nothing in the FAQ (Win32 or otherwise) and I didn't find anything
> in the File::Tools,

Where is that available? (Apparently not from CPAN, either.)

> Win32::API or File::Spec::Win32 modules either.

Looking on CPAN for modules matching /^File::/ brought nothing I
consider likely, so you may have to roll your own method or call an
external program.

Or write File::CopyDir yourself and submit it to CPAN!

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Mon, 18 Jun 2001 11:28:48 +0200
From: "H. Merijn Brand" <h.m.brand@hccnet.nl>
To: comp.lang.perl.misc
Subject: Re: Install Perl on HP
Message-Id: <Xns90C474C841F36Merijn@192.0.1.90>

Philip Newton <pne-news-20010617@newton.digitalspace.net> wrote in 
news:1q4pit4so3hcel3lrlqgkhcvm3grej7uo1@4ax.com:
>> *  I have previous verion perl install on my system,
> 
> Which one? The 4.036 that comes with HP-UX?

Should be no problem /if/ you did not choose "/usr/contrib/bin" as 
installation path for the binaries (not very likely though)

>>    so before I install, should I clean up previous version ?
> 
> With 4.036, that shouldn't be necessary.

Would be very bad for the system too, cause HP uses this for their updates.
(HP has plans to upgrade to perl5 for internal use ;-)

-- 
H.Merijn Brand    Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
using perl-5.6.1, 5.7.1 & 626 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
     WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/


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

Date: Mon, 18 Jun 2001 12:03:44 +0200
From: Philip Newton <pne-news-20010618@newton.digitalspace.net>
Subject: Re: Install Perl on HP
Message-Id: <tbkrit8819c20ebmt5m9dgs4ipo06jsak0@4ax.com>

On Mon, 18 Jun 2001 11:28:48 +0200, "H. Merijn Brand"
<h.m.brand@hccnet.nl> wrote:

> Philip Newton <pne-news-20010617@newton.digitalspace.net> wrote in 
> news:1q4pit4so3hcel3lrlqgkhcvm3grej7uo1@4ax.com:
> >>    so before I install, should I clean up previous version ?
> > 
> > With 4.036, that shouldn't be necessary.
> 
> Would be very bad for the system too, cause HP uses this for their updates.
> (HP has plans to upgrade to perl5 for internal use ;-)

They do? I thought the perl4 that comes with HP-UX was only for the
kernel debugger q4 and for nothing else (just like the cc that comes
with it is *only* for rebuilding the kernel, so it doesn't need any
steenking ANSI compliance).

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Mon, 18 Jun 2001 09:40:47 +0100
From: "Ben Holness" <bholness@nortelnetworks.com>
Subject: Re: Newbie Post : Flushing output for long scripts
Message-Id: <9gkeus$qn9$1@qnsgh006.europe.nortel.com>


"Dave Hoover" <redsquirreldesign@yahoo.com> wrote in message
news:812589bb.0106151236.40bd2d8c@posting.google.com...
> Ben Holness wrote:
>
> > I would like to give something to my users to show that it is actually
> > running.
>
> I'm assuming that this script is kicked off by a submit button.  Have
> the form action take the user to a static HTML page that displays,
> "Script is running, please be patient."  Then on that static HTML
> page, have an automatic redirect to your perl script.
>

This is actually fairly close to what I have ended up doing - I have used
frames so that I can print "Loading ... Please be patient" in the top frame
and then I have put the rest in the bottom frame. This means that the page
opens with the top frame straight away, which gives the users some peace of
mind.

Cheers,

Ben




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

Date: Mon, 18 Jun 2001 09:49:12 +0200
From: "JWP" <question_1@hetnet.nl>
Subject: open a http://www.domein.com.file
Message-Id: <uqpcBu89AHA.213@net037s.hetnet.nl>

Hello


How to do this.

Dos anyone know or where can i find it i look in cpan but !@#$%

^Sjaak




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

Date: Mon, 18 Jun 2001 10:07:09 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: open a http://www.domein.com.file
Message-Id: <3b2db645$1@e-post.inode.at>

JWP <question_1@hetnet.nl> wrote:

[Subject: Re: open a http://www.domein.com.file]
> How to do this.
>
> Dos anyone know or where can i find it i look in cpan but !@#$%

  use LWP::Simple;
  my $x = get("http://www.foo.bar/");

This might also work (but I don't recommend it, I just like the way
it looks):

  open (WEB, "GET http://www.foo.bar/ |") or die $!;


cheers,
stefan




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

Date: Mon, 18 Jun 2001 08:11:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: open a http://www.domein.com.file
Message-Id: <tkdritcsi61qr444qto9i8mrt7mmklmg0v@4ax.com>

JWP wrote:

>How to do this.
>
>Dos anyone know or where can i find it i look in cpan but !@#$%

	use LWP::Simple;
	$contents = get("http://www.domein.com/file");
	# or
	$status = getstore("http://www.domein.com/file",
	   "/path/to/filename.html");
	if($status != 200) {   print "Failure! status = $status\n");

If you don't already have LWP, look for the libwww suite on CPAN.

-- 
	Bart.


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

Date: Mon, 18 Jun 2001 12:42:26 +0300
From: Deneb Pettersson <Deneb.Pettersson@lmf.ericsson.se>
Subject: Re: Perl2Exe Decompiler?
Message-Id: <3B2DCD02.8E625171@lmf.ericsson.se>



> > > When you run a .exe file produced by perl2exe, I believe that it
> > > unpacks the contents into a temp directory (C:\WINDOWS\TEMP on my
> > > system) and then basically runs an embedded Perl interpreter on them.
> > > If you can somehow run the .exe but kill it before it has a chance to
> > > clean up those files, you might be able to recover the scripts you're
> > > trying to edit.  --Or maybe not, if I'm mistaken about how it works,
> > > but it might be worth a try.
> >
> > I watched my temp directory after executing one of my programs, but the
> > contents didn't change one bit.
>
> Hunh.  I found all kinds of interesting stuff in mine when my program
> crashed (Perl/Tk program).
>
> > Any other ideas? :-)
>
> I seem to be fresh out.  Oh, well, I tried.

You could run some tracker which monitros what is copied / installed to the harddisk
while you run the program you should get that out then. And you might jsut go ahead
and change the temp directory's write permissions... just to see how the program
behaves then .....

And you should look at the temp during the program. not after it....





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

Date: Mon, 18 Jun 2001 10:33:46 +0100
From: "John Imrie" <john.imrie@pa.press.net>
Subject: Re: Printing filenames that are in a directory
Message-Id: <tWjX6.1442$h45.8975@news.uk.colt.net>

<snip>
> > close THISDIR;
>
>    closedir THISDIR;
>
> (Question to the experts:  Does it make a difference?)
>

This frees up the handel so it can be used again, IMHA allways a good idea.

However to bullit proof the script a test should be done on the return value
like this

close THISDIR or die "error $! when attempting to close the directory
handel. Results from this script may not be valid"




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

Date: Mon, 18 Jun 2001 10:24:43 +0200
From: Dominique van der Wal <dvdw@plan.be>
Subject: Problem with redirect (with IE and not with Netscape)
Message-Id: <3B2DBACB.1D4F213C@plan.be>

Hi from Belgium,

I've a CGI wich insert some data in a database, after the insert I would
redirect to a html page.

I use the CGI module and I've try the two following methods :

1) print redirect("http://www.mybweb.com/admin/actionsadd_fr.stm");

or

2) my $destination = 'http://www.myweb.com/admin/newsmajart_fr.stm';
    $query = new CGI("");
    print $query->redirect(-uri=>$destination, -nph=>1);


It work fine with Netscape but with Microsoft IE, sometimes it works and
sometimes it doesn't. In fact, the first time it works but after it
doesen't.

Any idea to solve the problem ?

Thank you in advance
Dominique van der Wal




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

Date: Mon, 18 Jun 2001 09:52:00 GMT
From: Jenda Krynicky <Jenda@Krynicky.cz>
Subject: Re: Sending Attachments Via Sendmail
Message-Id: <1105_992857920@JENDA>

On 14 Jun 2001 07:13:14 GMT, vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse) wrote:
> On Wed, 13 Jun 2001 08:57:59 -0500, Mr. SunRay <nospam@hotmail.com> wrote:
> >> To answer your question: use the MIME::Lite module.
> >> 
> >Or the Mail::Sender module
> >
> 
> 
> The difference is that MIME::Lite can format a MIME message with
> attachments and everything.  Mail::Sender just sends it.
> 
> Villy

Are you sure? You'd better look before you say something :-)

Mail::Sender DOES encode attachments, print MIME headers AND send the message via
socket()s.

You probably confuse it with Mail::Sendmail or Mail::Mailer or something.

Jenda



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

Date: Mon, 18 Jun 2001 10:18:08 +0100
From: "John Imrie" <john.imrie@pa.press.net>
Subject: Re: setting @INC at perl compile time
Message-Id: <PHjX6.1441$h45.8906@news.uk.colt.net>

<snip>

> There is a bit too many repeats in there for me to feel comfortable
> 'make install'ing this. The whole thing about which recurse and which
> don't seems a bit under-documented, so I was looking for guidance. I
> can puzzle it out on my own.
>
> Elijah
> ------
> and will probably have to

Sorry I mis understood what you where asking.

IIRC the @INC array is set up by vareious paramaters in the Configure script
when Perl is compiled. You can edit the output of this befor you compile the
binery




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

Date: Mon, 18 Jun 2001 04:12:28 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting hash
Message-Id: <3B2DB7EC.2C555328@earthlink.net>

Edvard Majakari wrote:
> 
> On 16 Jun 2001, Sam Holden wrote:
> 
> > Ron Anderson <ronlanderson@earthlink.net> wrote:
> >>Using the sample hash below:
> >>
> >>$shash{"student1"} = join("\t", ("bob", "larson", "room5"));
> >>$shash{"student2"} = join("\t", ("ron", "anderson", "room4"));
> >>$shash{"student3"} = join("\t", ("dave", "lee", "room2"));
> >>$shash{"student4"} = join("\t", ("tim", "barker", "room3"));
> >>$shash{"student5"} = join("\t", ("roger", "farley", "room1"));
> 
> [snipp]
> 
> > You'd be much better off with something like:
> >
> > $shash{"student1"} = {fname => 'bob', lname => 'larson', room =>
> > 'room5'};
> 
> You're right, HoH would be more elegant IMO, too, but using plain
> strings using join() might be better if there are *lots* of students,
> this data structure has to be copied a lot or - or in any other case
> you have to take into account memory requirements. Hash of hashes may
> take lots of space due to internal structure of hashes.
> 
> In the case above, you could print given students sorted
> alphabetically by

> # not tested though, and at the moment I'm very tired..
> foreach (sort
>	# last name is at index 1
>	{ (split /\t/, $shash{$a})[1] cmp (split /\t/, $shash{$b})[1] }
>	keys %shash) {
>   print "key: $_, $shash{$_}\n";
> }

Wouldn't a Schwartzian Transform or Guttman Roswieler Transform be
faster here?

foreach (map {(unpack 'Z* a*')[1]} sort map {
		my $lname = (split /\t/ $shash{$_})[1];
		pack  'Z* a*', $lname, $_; } keys %shash) {
	print "key: $_, $shash{$_}\n";
}

> 
> Then again, I'm quite sure that calling split instead of plain hash
> lookups is considerably slower method, and somewhat more complicated.

GRT is still faster than doing
	sort { $shash{$a}{lname} <=> $shash{$b}{lname} } keys %hash

> I'd go for HoH alternative, or as Sam pointed out, you might just use
> an array, or LoH (list of hashes) actually.

I will, however, note that if HoH is used, the GRT becomes a tiny bit
simpler:

foreach (map {(unpack 'Z* a*')[1]} sort map
	{ pack 'Z* a*', $shash{$_}{lname}, $_ } keys %shash) {
	print "key: $_, $shash{$_}\n";
}

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Mon, 18 Jun 2001 09:31:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Sorting hash
Message-Id: <3B2DCA97.76CD6A23@acm.org>

Benjamin Goldberg wrote:
> 
> Wouldn't a Schwartzian Transform or Guttman Roswieler Transform be
> faster here?
> 
> foreach (map {(unpack 'Z* a*')[1]} sort map {
                        ^^^^^^^
You didn't pass an expression to unpack (it doesn't default to $_) and
in the template 'Z* a*' Z* grabs everything so the a* is superfluous.


>                 my $lname = (split /\t/ $shash{$_})[1];
>                 pack  'Z* a*', $lname, $_; } keys %shash) {
>         print "key: $_, $shash{$_}\n";
> }
> 
> >
> > Then again, I'm quite sure that calling split instead of plain hash
> > lookups is considerably slower method, and somewhat more complicated.
> 
> GRT is still faster than doing
>         sort { $shash{$a}{lname} <=> $shash{$b}{lname} } keys %hash
> 
> > I'd go for HoH alternative, or as Sam pointed out, you might just use
> > an array, or LoH (list of hashes) actually.
> 
> I will, however, note that if HoH is used, the GRT becomes a tiny bit
> simpler:
> 
> foreach (map {(unpack 'Z* a*')[1]} sort map
                        ^^^^^^^
Same as above.

>         { pack 'Z* a*', $shash{$_}{lname}, $_ } keys %shash) {
>         print "key: $_, $shash{$_}\n";
> }


John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 18 Jun 2001 09:42:56 GMT
From: Jenda Krynicky <Jenda@Krynicky.cz>
Subject: Re: supressing error messages in NT
Message-Id: <1104_992857376@JENDA>

On Mon, 11 Jun 2001 15:52:10 -0400, "John Hoerr" <jhoerr@resnet.gatech.edu> wrote:
> i can't find any documentation on suppressing error messages ala $output =
> `cmd 2>/dev/null`;  for a win32 environment.   Any thoughts on a good way to
> do this?
> 
> thanks,
> john
> 
> 

	cmd 2>nul

Notice the single "l" !

Jenda



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

Date: Mon, 18 Jun 2001 09:35:23 GMT
From: Jenda Krynicky <Jenda@Krynicky.cz>
Subject: Re: What is the ideal way to parse?
Message-Id: <1103_992856923@JENDA>

On Fri, 15 Jun 2001 10:01:45 +0200, "Frank Dessing" <F.J.Dessing@siep.shell.com> wrote:
> Hi,
> 
> I am looking for a way to parse variables into a scripts. The scripts can be
> unix or another language.
> 
> What I want to do looks like this. I have a long script with here and there
> a variable at a certain position in the line. The variables should be
> sometimes of a fixed format. The script can have the following structure.
> 
> === START_OF_SCRIPT
> command1 $variable1 remainder_of_command1
> command2
> $variable3 command3
> === END_OF_SCRIPT
> 
> At the moment I read the base script and search for $variable1, $variable2
> etc. and replace them with a s/// command. Subsequently I write the replaced
> lines to a new file. This is perfectly doable as long as the number of
> variables is small. If the number of variables gets larger the substitution
> approach starts to become more problematic.
> 
> Any ideas on more efficient solutions.
> 
> Thanks,
> 
> Frank Dessing

Store the values in a hash :

	$var{variable1} = "something";
	$var{variable2} = "something other"

then use s/// similar to this :

	$line =~ s/\$([\w_][\w\d_]*)/$var{$1}/g; 
	# variable names contain only letters, numerals and underscore
	# and start with a letter of underscore

Hope this is what you are after.

Jenda




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1151
***************************************


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