[9169] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2787 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 2 13:17:18 1998

Date: Tue, 2 Jun 98 10:00:28 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 2 Jun 1998     Volume: 8 Number: 2787

Today's topics:
        $salt=.... (urgent!) <lars-n@hsr.no>
    Re: $salt=.... (urgent!) <lanier@shell6.ba.best.com>
    Re: $salt=.... (urgent!) (Michael J Gebis)
    Re: $salt=.... (urgent!) <ajohnson@gpu.srv.ualberta.ca>
    Re: $salt=.... (urgent!) <rootbeer@teleport.com>
    Re: Best tool? (Abigail)
    Re: cgi Performance? <rootbeer@teleport.com>
    Re: Help in Proxy Server GET HTTP! <e78199@ceng.metu.edu.tr>
    Re: map in void context regarded as evil - suggestion (Jonathan Stowe)
    Re: map in void context regarded as evil - suggestion <rootbeer@teleport.com>
    Re: map in void context regarded as evil - suggestion (Chris Nandor)
    Re: map in void context regarded as evil - suggestion <tchrist@mox.perl.com>
    Re: map in void context regarded as evil - suggestion <tchrist@mox.perl.com>
    Re: Need Crontab <sdh1@anchor.hotmail.com>
    Re: Perl module for doing a unix 'which'? (Tom Grydeland)
    Re: Perl module for doing a unix 'which'? <tchrist@mox.perl.com>
    Re: Perl module for doing a unix 'which'? (Michael J Gebis)
        perl question dow.jones@home.se
    Re: perl question <jdporter@min.net>
    Re: Perl Scripts <rdg2@axe.humboldt.edu>
    Re: Perl Search Engine <jdf@pobox.com>
    Re: Perl-Frage (Jonathan Stowe)
        Piping in Win32 Perl... <pendsepr@pilot.msu.edu>
        processing a file with multiple eof <jshaye@facstaff.wm.edu>
    Re: processing a file with multiple eof <lanier@shell6.ba.best.com>
    Re: processing a file with multiple eof <rootbeer@teleport.com>
    Re: Save me a few days work of cut'n paste !! <jdporter@min.net>
    Re: simple question (Mark-Jason Dominus)
    Re: Sorting a Perl hash of complex records... (Larry Rosler)
    Re: Sorting a Perl hash of complex records... <jdporter@min.net>
    Re: Sorting a Perl hash of complex records... <danboo@negia.net>
    Re: String to hash utility anyone? ptimmins@netserv.unmc.edu
    Re: String to hash utility anyone? <jdporter@min.net>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 2 Jun 1998 17:48:32 +0200
From: "Lars" <lars-n@hsr.no>
Subject: $salt=.... (urgent!)
Message-Id: <6l177m$pj9$1@news1.c2i.net>

Kan anyone explain to me in "plain" english what the following does?

srand(time());

$salt=rand();
$salt=~s/\S\S(\S\S).*/$1/;
$crypted_pw=crypt($in{'passwd'),$salt);

I know it has something to do with crypting the text but I really need to
know in detail what it does. Does anyone have time to explain??

Lars





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

Date: Tue, 2 Jun 1998 09:17:11 -0700
From: "matthew d. p. k. lanier" <lanier@shell6.ba.best.com>
Subject: Re: $salt=.... (urgent!)
Message-Id: <Pine.BSF.3.96.980602091204.14895B-100000@shell6.ba.best.com>

so, larry, randal, and tom don't write in plain enough englist for you?
;)


> srand(time());
seeds the random numberber generator with the result of the current time

> 
> $salt=rand();
this functions gets a random number and stores it in $salt

> $salt=~s/\S\S(\S\S).*/$1/;
this searches for 2 white space charaters, 2 more white space characters,
and a bunch of stuff until the end of the string, and replaces all of that
with the 2'nd set of whitespace charaters.


> $crypted_pw=crypt($in{'passwd'),$salt);

this is encrypting the scalar contained in $in{'passwd'}, using the
previously computed $salt as the salt.  it's then storing it in
$crypted_pw.

wow, that's about as much english as i can muster for one day!

matt =)

 ........................................................
: matthew d. p. k. lanier : sf perl user's group       :
: matt@lanier.org         : sfpug-request@pootpoot.com :
: matt@saturn5.com        : http://www.pm.org          :
 ........................................................




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

Date: 2 Jun 1998 16:38:57 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: $salt=.... (urgent!)
Message-Id: <6l19r1$25p@mozo.cc.purdue.edu>

"matthew d. p. k. lanier" <lanier@shell6.ba.best.com> writes:

}> $salt=~s/\S\S(\S\S).*/$1/;
}this searches for 2 white space charaters, 2 more white space characters,
}and a bunch of stuff until the end of the string, and replaces all of that
}with the 2'nd set of whitespace charaters.

s/white ?space/non-whitespace/g;

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Tue, 02 Jun 1998 11:41:22 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: $salt=.... (urgent!)
Message-Id: <35742B32.33B5DD30@gpu.srv.ualberta.ca>

matthew d. p. k. lanier wrote:
!
[snip]

! > $salt=~s/\S\S(\S\S).*/$1/;
! this searches for 2 white space charaters, 2 more white space
! characters, and a bunch of stuff until the end of the string, and
! replaces all of that with the 2'nd set of whitespace charaters.

s/(white\s*space)/non-$1/g;

andrew


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

Date: Tue, 02 Jun 1998 16:51:29 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: $salt=.... (urgent!)
Message-Id: <Pine.GSO.3.96.980602094731.15370m-100000@user2.teleport.com>

On Tue, 2 Jun 1998, Lars wrote:

> Kan anyone explain to me in "plain" english what the following does?
> 
> srand(time());
> 
> $salt=rand();
> $salt=~s/\S\S(\S\S).*/$1/;
> $crypted_pw=crypt($in{'passwd'),$salt);
> 
> I know it has something to do with crypting the text but I really need to
> know in detail what it does. Does anyone have time to explain??

I'll be glad to explain part of it - the part after you read the manpages
and before you understand that code. :-)  That is, first, read what the
docs say about those functions and operators. Then, if you still don't
understand some part of what's going on, post here to ask what that
particular part means. Cheers! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 2 Jun 1998 15:09:48 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Best tool?
Message-Id: <6l14js$62j$1@client3.news.psi.net>

Jeremy D. Zawodny (jzawodn@wcnet.org) wrote on MDCCXXXVI September
MCMXCIII in <URL: news:m3zpfw39v5.fsf@peach.z.org>:
++ abigail@fnx.com (Abigail) writes:
++ 
++ > Stuart McDow (smcdow@arlut.utexas.edu) wrote on MDCCXXXIV September
++ > MCMXCIII in <URL: news:6kq9ke$sp7$1@ns1.arlut.utexas.edu>:
++ > ++ 
++ > ++ Probably a good web server and a good web browser. I'd use apache and
++ > ++ navagator.                       ^^^^^^^^^^^^^^^^
++ >    ^^^^^^^^^
++ > 
++ > Why don't you practise what you preach?
++ 
++ What are you suggesting?


It's like saying "Probably a good operating system. I'd use Windows 95".



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET", "http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content)) =~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: Tue, 02 Jun 1998 16:25:07 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: cgi Performance?
Message-Id: <Pine.GSO.3.96.980602092256.15370h-100000@user2.teleport.com>

On Tue, 2 Jun 1998, John McDermon wrote:

> It looks like the "bigger" machine is either hitting memory or CPU
> limits, but I can't figure out why. 

Don't the diagnostic messages from your scripts give you any ideas? 

> remove the nojunk from the return address to reply via email

remove the nojunk from the return address to get replies via email.  :-) 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 02 Jun 1998 17:57:14 +0300
From: Walid ALSAQAF <e78199@ceng.metu.edu.tr>
Subject: Re: Help in Proxy Server GET HTTP!
Message-Id: <357412CA.94077063@ceng.metu.edu.tr>

IT WORKED, thank you for your help..

Barry Margolin wrote:
> 
> In article <3572ABFD.16AD8E1B@ceng.metu.edu.tr>,
> Walid ALSAQAF  <e78199@ceng.metu.edu.tr> wrote:
> >Saying that my browser is not using a proxy caching mechanism, and that
> >I have to set up a proxy cache connection. I am not sure what this
> >means? Is there a special sequence of argument instead of "GET
> >/index.html HTTP/1.0"
> 
> When you use a proxy server, you have to send the full URL in the command,
> e.g.
> 
> GET http://servername/index.html HTTP/1.0
> 
> --
> Barry Margolin, barmar@bbnplanet.com
> GTE Internetworking, Powered by BBN, Cambridge, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.

-- 
/*********************************************/
Walid ALSAQAF

METU 
Computer Engineering Department
mailto:e78199@ceng.metu.edu.tr
http://www.ceng.metu.edu.tr/~e78199/Walid
ICQ # : (9762042)
/*********************************************/


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

Date: Tue, 02 Jun 1998 16:04:01 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <35741f81.7197152@news.btinternet.com>

On 2 Jun 1998 12:56:47 GMT, Tom Grydeland wrote :

>
>Many OPs in Perl know what context they're called in and modify their
>behaviour to fit the requirement.  For instance, C<scalar keys %hash>

Just a thought but shouldnt POD markup be deprecated in usenet
postings just as HTML is ?

/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>



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

Date: Tue, 02 Jun 1998 16:28:54 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <Pine.GSO.3.96.980602092654.15370i-100000@user2.teleport.com>

On 2 Jun 1998, Tom Grydeland wrote:

> The major complaint about using C<map> in void context is that it
> creates a (possibly large) return value which is then discarded.
> 
> Wouldn't it be possible to make C<map> recognise when it's called in
> void context and *not* create the return list in these cases?

Sure, that's possible. Please use the perlbug program to submit your patch
to the Perl developers when you've finished it. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 02 Jun 1998 16:51:03 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <pudge-0206981245220001@192.168.0.3>

In article <35741f81.7197152@news.btinternet.com>,
Gellyfish@btinternet.com (Jonathan Stowe) wrote:

# On 2 Jun 1998 12:56:47 GMT, Tom Grydeland wrote :
# 
# >
# >Many OPs in Perl know what context they're called in and modify their
# >behaviour to fit the requirement.  For instance, C<scalar keys %hash>
# 
# Just a thought but shouldnt POD markup be deprecated in usenet
# postings just as HTML is ?

Why?

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])


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

Date: 2 Jun 1998 16:35:49 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <6l19l5$kbr$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Gellyfish@btinternet.com (Jonathan Stowe) writes:
:Just a thought but shouldnt POD markup be deprecated in usenet
:postings just as HTML is ?

You've *got* to be kidding.  Whyever would you think that we should
deprecate *simple* text markups?  It's not like we have _Elements
of Typography_ breathing down our necks.

--tom
-- 
    "Winter is worth its wait in cold." --Larry Wall


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

Date: 2 Jun 1998 16:44:34 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: map in void context regarded as evil - suggestion
Message-Id: <6l1a5i$kbr$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Tom.Grydeland@phys.uit.no (Tom Grydeland) writes:
:The major complaint about using C<map> in void context is that it
:creates a (possibly large) return value which is then discarded.

No, the major complaint is backwards logic confusing people.

    do {{
	open(OWNER, "< $whosegot") || last; 
	my $lockee = <OWNER>;
	chomp($lockee);
	printf STDERR "%s $0\[$$]: lock on %s held by %s\n",
	    scalar(localtime), $pathname, $lockee;
	close OWNER;
    }} if $Debug;

I can't see why people use

    map  { s/foo/bar/ } @list;
    grep { s/foo/bar/ } @list;

when they could more clearly write:

    for (@list) { s/foo/bar/ } 

Put the important thing first.

--tom
-- 
    "Don't let it get to you.  Shout happens." --Larry Wall


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

Date: Tue, 2 Jun 1998 11:17:39 -0400
From: "Scott" <sdh1@anchor.hotmail.com>
Subject: Re: Need Crontab
Message-Id: <6l158o$uc7$1@camel0.mindspring.com>


nospam@death.to.spammers.org wrote in message
<6kuult$cl4@eccws1.dearborn.ford.com>...
>In article <6kutft$mq6@sjx-ixn4.ix.netcom.com>,
> ralber@ix.netcom.com (Rick Alber) writes:
>>I just moved my domain to a new ISP (Mindspring)
>>[...] thereby triggering a mailing to about
>>15,000 people. That mailing just *might* promote the service that
>>provides the crontab.
>
>Out of curiosity (and maybe for humor value) are these two events
>related?


Yeah, Mindspring doesn't appreciate mass mailings.




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

Date: 2 Jun 1998 15:23:57 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: Perl module for doing a unix 'which'?
Message-Id: <slrn6n868c.2m4.Tom.Grydeland@mitra.phys.uit.no>

On Tue, 2 Jun 1998 10:34:07 -0400,
Brian J. Sayatovic <bjs@iti-oh.com> wrote:
>     Has anyone come across a comprehensive module to do the equivalent of a
> UNIX which in Perl for UNIX/Win32?

Dunno about W*n, but here's a Unix 'where' (listing all occurences)

perl -e 'print map "$_/$ARGV[0]\n", grep -e "$_/$ARGV[0]",
	split ":", $ENV{PATH}' command_to_find

(where 'command_to_find' is the command to find).
Extracting the first one (which) is left as an exercise for the reader :-)


> the ls command, or perhaps a statement that it is an alias.

Perl has no way of knowing about your shell's aliases without parsing an
rc file.  That is better left to the shell.

> However, I'd like to find a
> comprehensive module that does this and more.  For example, on NT with
> Command Extensions, one have have any extension be executable instead of
> just .exe, .com, .bat and .cmd.

ah, well.  The joys of filename-sensitive systems.

Perhaps you should look into File::Find then.

>     I suppose if one doesn;'t exist I can write one, but I'd rather use a
> pre-existing one if there is one out there.

Have you looked at the module list on CPAN?

> Brian Sayatovic.

-- 
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
      - Do radioactive cats have 18 half-lives? -


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

Date: 2 Jun 1998 16:33:06 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl module for doing a unix 'which'?
Message-Id: <6l19g2$kbr$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, "Brian J. Sayatovic" <bjs@iti-oh.com> writes:
:    Has anyone come across a comprehensive module to do the equivalent of a
:UNIX which in Perl for UNIX/Win32?

    #!/usr/bin/perl
    # pgrep - grep for files in your path
    chop($cwd = `pwd`) unless $cwd = $ENV{'PWD'};
    $regexp = shift || die "usage: $0 regexp\n";
    for $dir (split(/:/,$ENV{'PATH'})) {
	chdir($dir =~ m#^/# ? $dir : "$cwd/$dir") || next;
	opendir(DOT, '.') || next;
	while ($_ = readdir(DOT)) {
	    next unless /$regexp/o;
	    next unless -f;
	    next unless -x _;
	    print "$dir/$_\n";
	} 
    }

This cross-platform program has been tested on BSD, Linux, *and* SunOS.
It has not, of course, been tested on CP/M or MVS.

--tom
-- 
     This is UNIX; if you can't get the sources, it isn't freeware.
     --Peter Salus


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

Date: 2 Jun 1998 16:33:19 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Perl module for doing a unix 'which'?
Message-Id: <6l19gf$24o@mozo.cc.purdue.edu>

Tom.Grydeland@phys.uit.no (Tom Grydeland) writes:

}> the ls command, or perhaps a statement that it is an alias.

}Perl has no way of knowing about your shell's aliases without parsing an
}rc file.  That is better left to the shell.

$aliases=`csh -c alias`;

Or something like that...custom tuned per shell, maybe based upon
the results of $ENV{'SHELL'}.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Tue, 02 Jun 1998 15:47:44 GMT
From: dow.jones@home.se
Subject: perl question
Message-Id: <6l16r1$oub$1@nnrp1.dejanews.com>

Hallo. I have a small perl problem wich I can't solve. I would appreciate if
someone could have a look at it...

It goes like this:
==================

1. I have one text file with the following text:

price>100<
object>dog<
obj_id>1<
seller>mr Burns<

price>150<
object>cat<
obj_id>2<
seller>mr Arnold<

price>105<
object>dog<
obj_id>1<
seller>mr X<

 ...

2. Then I also have another text file that looks like this:

theseller>mr B<
what>dog<
id>1<
theprice>105<

theseller>mr C<
what>dog<
id>1<
theprice>90<

 ...

(note. The second textfile does not have the same structure, but both
textfiles have the same information types)

3. I want to search thru the both textfiles and find out which objects there
are and where I can buy each object as cheep as possible.The result should be
the following text:

----result.txt---
dog, 1, mr C, 90
cat, 2, mr Arnold, 150
----result.txt---

4. My first problem is that I don't know the exact exact expression to extract
the information. I've tried the following:

while ($first_file =~
/price>(.*)<(.*)object>(.*)<(.*)obj_id>(.*)<(.*)seller>(.*)/g)
{}

but I suppose that it isn't a good solution because I'm not a perl expert...
does anyone have a better solution?

5. My second problem is that I don't know how to store the information from
the first text-file. I need to do that because I have to compare the
information extracted from the second textfile to the first. I was thinking
maby to create a Class called "Animal" or something... just so that I can
store the information. Is that a good solution?

Please answer if you have any ideas.

// Dow

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 02 Jun 1998 16:17:16 GMT
From: John Porter <jdporter@min.net>
Subject: Re: perl question
Message-Id: <35742739.2C75@min.net>

dow.jones@home.se wrote:
> 
> Hallo. I have a small perl problem wich I can't solve. I would appreciate if
> someone could have a look at it...
> 
> It goes like this:

Smells like homework.

John Porter


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

Date: Tue, 2 Jun 1998 08:53:41 -0700
From: "Ryan G." <rdg2@axe.humboldt.edu>
Subject: Re: Perl Scripts
Message-Id: <6l1731$6i4$1@hades.csu.net>

Also check out http://www.cgi-resources.com.  It's a great CGI script
collection in a bunch of different languages, perl being the most popular
there.

Ryan Grace


Jason Stephenson wrote in message ...
>At the risk of tooting my own horn, I've put together a page of links to
>Perl stuff. It's a work in progress (as is everything on the web), but it
>should get you started looking around.
>
>    http://jason.stephenson.net/perl.htm




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

Date: 02 Jun 1998 10:44:47 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Brandy Skirvin <bskirvin@wpo.iupui.edu>
Subject: Re: Perl Search Engine
Message-Id: <3edndd00.fsf@mailhost.panix.com>

Brandy Skirvin <bskirvin@wpo.iupui.edu> writes:

> Please help me with this, I don't know any PERL.

It's considered rude to ask this newsgroup to write code for you.
This newsgroup is for the discussion of Perl language issues.  We can
help you learn Perl, but that's not at all what you're asking for.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/


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

Date: Tue, 02 Jun 1998 16:04:03 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Perl-Frage
Message-Id: <3574203a.7382194@news.btinternet.com>

On 2 Jun 1998 06:50:11 GMT, J|rgen P|nter wrote :

>In article <3570b51f.53672600@news.btinternet.com>, Gellyfish@btinternet.com 
>says...
>>
>>That will be ( courtesy of: http://babelfish.altavista.digital.com ):
>
>[snip horrible translation]
>
>>I didnt like the bit where it says " the user must die" - but hey this
>>guy probably works for Microsoft (or IG Farben).. 
>

It was simply a piece of satire.  I wouldnt have posted if the
translation hadnt been quite so horrible.  Lighten up.

/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>



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

Date: Tue, 02 Jun 1998 11:58:37 -0400
From: Prasanna Pendse <pendsepr@pilot.msu.edu>
Subject: Piping in Win32 Perl...
Message-Id: <3574212D.93@pilot.msu.edu>

I am trying to pipe some ouput into bc (nt port) like this:

chomp(@data = qx!$cat c:\inetpub\cgi-bin\a.bc | $bc!);
$num_d = scalar @data;
$d = join("\n", @data);
print "num_d: $num_d\n";
print $d;

this works if I run it on the commandline, but can't see the output
through my browser... (@data is empty and $num_d is 0).

Let me know what I did wrong (or if this is a Perl for Win32 problem and
if there is any way to get around it...)

-Prasanna


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

Date: Tue, 02 Jun 1998 11:32:40 -0400
From: Scott Hayes <jshaye@facstaff.wm.edu>
Subject: processing a file with multiple eof
Message-Id: <35741B17.D9BECAB6@facstaff.wm.edu>

I need to process a file that has email messages in it. Each message is
separated by an EOF (DOS CTRL-Z).  Win32Perl stops after reading the
first EOF. I have tried testing for EOF and reading past it without any
luck. The solution is simple, but I just can't see it.
Any help would be appreciated! Thanks!
--Scott Hayes        jshaye@greyhawk.ts.wm.edu

------code----
# Check arguments
# usage example fixcpself.pl copyslf2.pmm txjeff@mail.wm.edu
die "Usage: $0 Folder-name email-address\n" if ($#ARGV != 1);

$_ = $ARGV[0];

$FOLDER = shift; # Get the first argument
$EMAIL = shift;  # Get the second argument

# If the folder does not exist, quit
die "$0: $FOLDER does not exist\n" if (! -f $FOLDER);

open (FOLDER,"$FOLDER");
open (OUTFILE,">tempfold.pmm");
while (<FOLDER>)
{

    if ( /^From:/)
    {
        print OUTFILE "From: $EMAIL\n";
    }
    else
    {
        print OUTFILE $_;
    }
    if (eof (FOLDER))  # test for EOF
    {
        $JUNK = getc (FOLDER);     # Read past EOF
     }
}
close (FOLDER);
close (OUTFILE);




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

Date: Tue, 2 Jun 1998 09:04:57 -0700
From: "matthew d. p. k. lanier" <lanier@shell6.ba.best.com>
Subject: Re: processing a file with multiple eof
Message-Id: <Pine.BSF.3.96.980602085844.14895A-100000@shell6.ba.best.com>

scott-

you need to do an explicit assignment within your while clause.

you do the following:

while (<FOLDER>) {

which is exactly equivelant to
while (defined ($_ = <FOLDER>)) {

your script fails on the defined, because eof, as far as i know, evaluates
to an undefined value (someone please correct me here if i'm wrong).

the correct way to do this would be:

while ($_ = <FOLDER>) {

  next unless defined;  # this will goto the next line if the current line
is undefined.

  do your stuff here
}

what you need to make sure of, in this method, is that you don't get into
an infinite loop.  you need to build in some logic that determines if
you've eof'd twice in a row.  at that point, you break out.

hope this is a start!

 >
------code---- > # Check arguments
> # usage example fixcpself.pl copyslf2.pmm txjeff@mail.wm.edu
> die "Usage: $0 Folder-name email-address\n" if ($#ARGV != 1);
> 
> $_ = $ARGV[0];
> 
> $FOLDER = shift; # Get the first argument
> $EMAIL = shift;  # Get the second argument
> 
> # If the folder does not exist, quit
> die "$0: $FOLDER does not exist\n" if (! -f $FOLDER);
> 
> open (FOLDER,"$FOLDER");
> open (OUTFILE,">tempfold.pmm");
> while (<FOLDER>)
> {
> 
>     if ( /^From:/)
>     {
>         print OUTFILE "From: $EMAIL\n";
>     }
>     else
>     {
>         print OUTFILE $_;
>     }
>     if (eof (FOLDER))  # test for EOF
>     {
>         $JUNK = getc (FOLDER);     # Read past EOF
>      }
> }
> close (FOLDER);
> close (OUTFILE);
> 
matt =)

 ........................................................
: matthew d. p. k. lanier : sf perl user's group       :
: matt@lanier.org         : sfpug-request@pootpoot.com :
: matt@saturn5.com        : http://www.pm.org          :
 ........................................................




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

Date: Tue, 02 Jun 1998 16:44:25 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: processing a file with multiple eof
Message-Id: <Pine.GSO.3.96.980602094404.15370k-100000@user2.teleport.com>

On Tue, 2 Jun 1998, Scott Hayes wrote:

> I need to process a file that has email messages in it. Each message is
> separated by an EOF (DOS CTRL-Z).  Win32Perl stops after reading the
> first EOF. 

binmode? Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 02 Jun 1998 15:14:38 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Save me a few days work of cut'n paste !!
Message-Id: <35741889.1B5E@min.net>

Kidon Sull wrote:
> 
> I need to process quite a few proprietary formatted, tagged
> files, for search and replace job as follows :

Don't you think it's time you learned to do this yourself?


> 1. Parse and extract string between E1 tag and [a or F or
> l or g] tag ignoring everything between them, which leaves
> a document title.
> 
> 2. Repalce the result of 1 with EDT$result.
> 
> 3. Leave everyting else intact and save as a new file.
> 
>  is Ascii 30 (start of a tag) and  is Ascii 31 (end of a tag).

Which is 036 and 037 octal, respectively.

% perl -pi.bak -00 -e 's/\036E1(\036)(?=.*\037)[aFlg]/$1EDT$2/s'
filename

This will replace "E1Rubber Soula" with "EDTRubber Soul".

This modifies the file in place, saving the original with a .bak
appended.

hth,
John Porter


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

Date: 2 Jun 1998 12:14:04 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: simple question
Message-Id: <6l18cc$jo3$1@monet.op.net>
Keywords: conveyor corpora Gaithersburg illustrate


In article <MPG.fdcac90e4bea3db989680@hplntx.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>> You use the `mkdir' function.
>> If the directory already exists, then it'll fail, but who cares?
>
>I think I would care, because I would have to examine the failure code to 
>see if it failed for some other reason than prior existence (such as 
>permissions).  

You have to examine the failure code anyway, so what's the problem?
The existence check beforehand is pointless.

>Otherwise I couldn't be sure the directory existed after the 'mkdir'.

Well, if you really want to be sure that the directory exists after
the `mkdir', why not do the existence check afterwards?  Doing one
beforehand doesn't make any sense.



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

Date: Tue, 2 Jun 1998 08:41:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting a Perl hash of complex records...
Message-Id: <MPG.fddbcf336a54e56989683@hplntx.hpl.hp.com>

In article <3574103F.374D@min.net>, jdporter@min.net says...
> wiklund@my-dejanews.com wrote:
 ...
> > What I wish to do is sort the hash according to the
> > numeric value of "Time", the sorted result should look
> > like this:
> > TestA
> >  Type = B
> >  Time = 13,5ak
> >  Type = A
> >  Time = 14,7ak
> > TestB
> >  Type = A
> >  Time = 16,2M
> >  Type = B
> >  Time = 17,2M
> }
 ...
> sub digits_of {
>   my $s = shift;
>   $s =~ s/\D//g; # remove all non-digits
>   $s;
> }

This would sort 16,10 higher than 17,2 and might not be what is wanted.  
One could split the number at the comma and weight the first part very 
high:

sub digits_of {
  shift =~ /(\d+),(\d+)/;
  1000 * $1 + $2;
}
 
> sub by_time {
>   # each member of a 'Result' array is a hashref, having a
>   # member named 'Time'.
>   # compare them numerically, using all (and only) the digits:
>   digits_of($a->{Time}) <=> digits_of($b->{Time})
> }

This would recompute the sort keys unnecessarily.  Following the 
principle of the Schwartzian transform without the syntax, this caches 
the keys:

  ($key{$a->{Time}} ||= digits_of($a->{Time})) <=>
  ($key{$b->{Time}} ||= digits_of(ba->{Time}))

> hth,
> John Porter

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Tue, 02 Jun 1998 16:22:38 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Sorting a Perl hash of complex records...
Message-Id: <35742879.780B@min.net>

Larry Rosler wrote:
> 
> This would sort 16,10 higher than 17,2 and might not be what is wanted.
> One could split the number at the comma and weight the first part very
> high:
> 
> sub digits_of {
>   shift =~ /(\d+),(\d+)/;
>   1000 * $1 + $2;
> }

Good point.  
Maybe there's more info we can use, like maybe
'M' means 'mega' and 'ak' means 'kilo' or something.


>   ($key{$a->{Time}} ||= digits_of($a->{Time})) <=>
>   ($key{$b->{Time}} ||= digits_of(ba->{Time}))

Yep, that caches them in a hash named %key.
Might want to be explicit about where %key is, and to make
sure it's empty before entering the outer loop.

John Porter


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

Date: Tue, 02 Jun 1998 12:27:06 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Sorting a Perl hash of complex records...
Message-Id: <357427DA.BB4AEE28@negia.net>

Larry Rosler wrote:
> 
> In article <3574103F.374D@min.net>, jdporter@min.net says...
>
> > sub digits_of {
> >   my $s = shift;
> >   $s =~ s/\D//g; # remove all non-digits
> >   $s;
> > }
> 
> Using this algorithm, 16,10M would sort higher than 17,2M.  If this isn't
> what is wanted, there are several ways to fix it -- for example, by
> splitting the fields on the comma and weighting the first field very
> high:
> 
> sub digits_of {
>     shift =~ /(\d+),(\d+)/;
>     1000 * $1 + $2;
> }

why not just replace the comma with a dot?

sub digits_of {
    $_ = shift;
    tr/,A-Za-z/./d;
    $_;
}

> 
> > sub by_time {
> >   digits_of($a->{Time}) <=> digits_of($b->{Time})
> > }
> 
> This would recompute the same sort key many times.  Using the principle
> of the Schwartian transform without the syntax, the keys could be cached:
> 
>   ($key{$a->{Time} ||= digits_of($a->{Time})) <=>
>   ($key{$b->{Time} ||= digits_of($b->{Time}))

and to put it all together:

for (sort keys %EXPERIMENTS) {
  print "$_\n";
  print map { $_->[0]->{'Type'}, "\n", $_->[0]->{'Time'}, "\n"  }
        sort { $a->[1] <=> $b->[1] }
        map { $_ = [$_, $_->{'Time'}]; $_->[1] =~ tr/,A-Za-z/./d; $_ }
        @{ $EXPERIMENTS{$_}{'Result'} };
}

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Tue, 02 Jun 1998 15:06:04 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: String to hash utility anyone?
Message-Id: <6l14cs$lch$1@nnrp1.dejanews.com>

I can't make myself think about this until I know why you would want to do
this. Wouldn't it be impossible to (usefully) ever have more than one file in
any particular directory given this scheme?.

eg: if you have file2.txt and file3.txt in dir1/sdir2/

$hash{'dir1'}{'sdir2'} = 'file2.txt';
$hash{'dir1'}{'sdir2'} = 'file3.txt';

The reference to file2.txt is now lost.

Will you ever only have one file in a directory? Can you elaborate further?

Thanks,

Patrick Timmins
U. Nebraska Medical Center

In article <6kv8c7$h5d$1@malgudi.oar.net>,
  "Eric Youngquist" <ewy@iti-oh.com> wrote:
>
> (Forgive me if this is a repost.  My first attempt resulted in an error)
>
> I would like to convert a string to a hash where keys are created based on a
> delimiter.  Before I write it myself, I was wondering if it has already been
> done before.
>
> Basically, I have the following strings
>
>     "dir1/sdir1/sdir11/file11.txt"
>     "dir1/sdir2/file2.txt"
>     "dir1/sdir3/sdir33/sdir333/file333.txt"
>
> and I would like to place them in a hash based on the delimiter "/":
>
>     $hash{dir1}{sdir1}{sdir11}=file11.txt
>     $hash{dir1}{sdir2}=file11.txt
>     $hash{dir1}{sdir3}{sdir33}{sdir333}=file333.txt
>
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 02 Jun 1998 15:28:03 GMT
From: John Porter <jdporter@min.net>
Subject: Re: String to hash utility anyone?
Message-Id: <35741BAF.7B5B@min.net>

Eric Youngquist wrote:
> 
>     "dir1/sdir1/sdir11/file11.txt"
>     "dir1/sdir2/file2.txt"
>     "dir1/sdir3/sdir33/sdir333/file333.txt"
> 
> and I would like to place them in a hash based on the delimiter "/":
> 
>     $hash{dir1}{sdir1}{sdir11}=file11.txt
>     $hash{dir1}{sdir2}=file11.txt
>     $hash{dir1}{sdir3}{sdir33}{sdir333}=file333.txt

That's interesting.

sub add_to_hash {
  my( $hashref, $filename ) = @_;
  my @p = split( /\//, $filename );
  while ( @p ) {
    $hashref = ( $hashref->{shift(@p)} = {} );
  }
}

my %hash;
for ( @filenames ) {
  add_to_hash( \%hash, $_ );
}

hth,
John Porter


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

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

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