[11240] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4840 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 7 03:07:31 1999

Date: Sun, 7 Feb 99 00:00:21 -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           Sun, 7 Feb 1999     Volume: 8 Number: 4840

Today's topics:
        $x %= 1000 always 295? <xeno@bigger.aa.net>
    Re: $x %= 1000 always 295? <rra@stanford.edu>
        Comma insertion in numbers, 333,333 <xeno@bigger.aa.net>
    Re: Comma insertion in numbers, 333,333 <allan@due.net>
    Re: DBI - Creating an array of results from a query <skovran@goto.com>
        DBM Help <jjarrett@ecpi.com>
        Encrypting a password <farber@admin.f-tech.net>
    Re: find where .pl was called from <rra@stanford.edu>
        Getting Perl to work with WinNT PWS <newmans@mindspring.com>
    Re: Help - Why doesn't this work? <rra@stanford.edu>
        Help: How to trim the blanks of a string at the beginni <leitang@sprynet.com>
    Re: Help: How to trim the blanks of a string at the beg <allan@due.net>
    Re: Help: How to trim the blanks of a string at the beg <allan@due.net>
        Java/Perl Lingo. <ekihn@bewellnet.com>
        keeping track of members logged in <nospam-seallama@mailcity.com>
    Re: keeping track of members logged in <paul@rainbow.nwnet.co.uk>
        newbie: Perl Book (Cookbook) <jjarrett@ecpi.com>
        No such file or directory <GLEdwards@christianfamilies.net>
    Re: Perl5.005002 Broken on number passing? <xeno@bigger.aa.net>
    Re: Perl5.005002 Broken on number passing? (Alan Barclay)
        Please Help Quickly <dkisting@cc.edu>
    Re: Program needs compactification (Peter J. Kernan)
    Re: Program needs compactification <uri@home.sysarch.com>
        Redirecting STDOUT <dmdp@miracle.net>
    Re: Redirecting STDOUT <rra@stanford.edu>
    Re: regex - matching acros lines (Ronald J Kimball)
    Re: What's happening with this hash? (Ronald J Kimball)
    Re: What's happening with this hash? (John Moreno)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 7 Feb 1999 04:26:45 GMT
From: Xeno Campanoli <xeno@bigger.aa.net>
Subject: $x %= 1000 always 295?
Message-Id: <79j4m5$dgp$1@slave3.aa.net>

I've got a large number $x, say 12341234123412341

Now when I $x %= 1000, I always get 295.  What gives?

I'd like to use integer arithmatic to divide an integer into comma
separable sequences of three numbers.  Apparently this is impossible in
Perl 5?

-- 
Xeno Campanoli
Email:	xeno@aa.net	(Web pages:  http://www.aa.net/~xeno)


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

Date: 06 Feb 1999 21:11:28 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: $x %= 1000 always 295?
Message-Id: <yld83mx0fz.fsf@windlord.stanford.edu>

Xeno Campanoli <xeno@bigger.aa.net> writes:

> I've got a large number $x, say 12341234123412341 Now when I $x %= 1000,
> I always get 295.  What gives?

Modulo arithmatic in Perl doesn't work correctly on numbers that are
larger than the size of an integer on your platform, since Perl internally
stores such numbers as floating point numbers and % doesn't understand
floating point.

There's been discussion on perl5-porters of the merits and problems with
fixing this (probably by going to fmod() for floating point numbers), but
currently % in Perl is basically % in C.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 7 Feb 1999 03:05:59 GMT
From: Xeno Campanoli <xeno@bigger.aa.net>
Subject: Comma insertion in numbers, 333,333
Message-Id: <79ivun$vlk$1@slave2.aa.net>

I know I knew this before, but now I don't and I can't figure it out.

If I've got:

$x = "123123123123123";

and I want:

$y eq "123,123,123,123,123"

generated from the above $x, what do I do?  I know I can do this
awful and expensive constructions using:

@x = split(//,$x);
@rx = reverse @x;
$z;
@a;
foreach $xpart ( @rx )
{
    $z .= $xpart;
    if ( length($z) == 3 )
    {
	push(@a,$z);
	$z = "";
    } 
}
push(@a,$z);
@b = reverse @a;
$c = join ",", @b;

and I almost wonder if I could do it more efficiently in C.  I'm almost
sure I can, which for Perl means do it with substr piece by piece.  Isn't
there a way to do it with regular expressions or something that is fast
and easy to understand?

Thank you for any feedback.  
-- 
Xeno Campanoli
Email:	xeno@aa.net	


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

Date: Sat, 6 Feb 1999 22:26:58 -0500
From: "Allan M. Due" <allan@due.net>
Subject: Re: Comma insertion in numbers, 333,333
Message-Id: <eK7v2.673$L1.13873@nntp1.nac.net>

Xeno Campanoli wrote in message <79ivun$vlk$1@slave2.aa.net>...
:I know I knew this before, but now I don't and I can't figure it out.
:If I've got:
:$x = "123123123123123";
:and I want:
:$y eq "123,123,123,123,123"
:generated from the above $x, what do I do?  I know I can do this
:awful and expensive constructions using:


[snip the rest of the code]

You know, there is a reason the FAQ is called a FAQ.  Maybe it should be
called SHF (Start Here First) <g>.

perlfaq5:  "How can I output my numbers with commas added?"

HTH

AmD





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

Date: Sat, 06 Feb 1999 18:12:13 -0800
From: Steven Skovran <skovran@goto.com>
Subject: Re: DBI - Creating an array of results from a query
Message-Id: <36BCF67D.304FA378@goto.com>

Gary O'Keefe wrote:
> now I want to store
> the results in an array called @results. Here's what I'm doing:
> 
> while ( @{ $results[++$#results] = \( $sth -> fetchrow_array ) } ) {}
> 
> and when I try to dereference the results from the array I get back that the
> contents of the array are not references to arrays.

You may find that "@results=@{$sth->fetchall_arrayref()}" will do what
you want. fetchall_arrayref() returns a reference to an array of array
references.
    Steven Skovran


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

Date: Sun, 07 Feb 1999 01:39:40 -0500
From: "John T. Jarrett" <jjarrett@ecpi.com>
Subject: DBM Help
Message-Id: <36BD352B.438274DE@ecpi.com>

Alright, I finally got a book, got perl installed on my win machine so I
can see the docs (even though work on a Unix over the net)....

Thanks to ORA's Perl Cookbook - and Tom Christiensen - I know I can use
NDBM, ODBM, and SDBM.

Which should I use for a few thousand line database with 50 fields? Do
they offer security or encryption? And should use a different one for a
little database (like passwords)?

I ___know____ I should be using Msql or better, but can't install on
this server.

TIA,
John



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

Date: Sat, 6 Feb 1999 23:55:39 -0500
From: Paul Farber <farber@admin.f-tech.net>
Subject: Encrypting a password
Message-Id: <Pine.LNX.3.96.990206235300.646A-100000@admin.f-tech.net>

Hello all

I know that PERL 5.002 supoprts the crypt() function, and I have seen many
examples of how to compare a password (the one in PERLDOC and the PERL
book).  But the LINUX adduser -p function for a script I am writing
requires the encryped password.

How do a get an appropiat SALT vale and how does the CRYPT() function get
called to return the encryped value?

Any pointer appreciated!

Paul D. Farber II
Farber Technology
717-628-5303
farber@admin.f-tech.net



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

Date: 06 Feb 1999 20:52:55 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: find where .pl was called from
Message-Id: <ylogn6x1aw.fsf@windlord.stanford.edu>

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

> Is there any way for a perl script to know where it has been called
> from?  (specifically called from a #exec SSI)?

What do you mean by "where it has been called from"?  On Unix, you can
determine what your parent process is, and possibly your process group
leader.  You can also get the possibly inacurrate path that the script
*thinks* it was called at.  Are either of those what you're looking for,
or are you trying to get something different?

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 6 Feb 1999 22:59:28 -0600
From: "news.mindspring.com" <newmans@mindspring.com>
Subject: Getting Perl to work with WinNT PWS
Message-Id: <79j6fr$el7$1@camel25.mindspring.com>

I am trying to get a simple perl script to run on NT so that I can begin
learning more about perl.  The script I am trying to run is:

#!/usr/bin/perl
print <<END_of_multiline_text;
Content-type: text/html

<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>
<H1>Greetings, Terrans!</H1>
</BODY>
</HTML>

END_of_multiline_text


However, when I point my browser (using local PWS) I see the #! and
everyting but the END_of_multiline_text entries.  Is there an option that I
forgot to check.  I have already made sure that the reference to the
d:\InetPub\cgi-bin\ is executable and aliased to \cgi-bin.

Any other ideas?  Thanks,
Steve




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

Date: 06 Feb 1999 20:51:42 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Help - Why doesn't this work?
Message-Id: <ylr9s2x1cx.fsf@windlord.stanford.edu>

As an aside...

Egon Kraaikamp <kraaikae@xs4all.nl> writes:

>         push( @{$DBCat[$i++]}, @Record );

The line:

        push (@DBCat, [ @Record ]);

is, unless I've messed something up, exactly equivalent to this line,
except that you don't have to keep a counter.  You're taking the array
@DBCat, accessing the $i'th element, treating that element as an anonymous
array, and pushing all of @Record into that anonymous array.  Since @DBCat
starts out empty, this creates a new anonymous array and pushes all of the
contents of @Record into that array.

Just creating an anonymous array containing the elements of @Record by
doing [ @Record ] is easier, and then you can just push that onto the end
of @DBCat and don't have to count.

There are exceptions, but in *general* if you're using index variables
like $i in Perl, you're probably doing more work than you have to do.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 6 Feb 1999 21:33:44 -0400
From: "LEI TANG" <leitang@sprynet.com>
Subject: Help: How to trim the blanks of a string at the beginning and the end.
Message-Id: <79itif$n3j$1@juliana.sprynet.com>

I want to trim the blanks at the beginning and the end of a string, and also
replace the blanks with only one blank in the middle of the string. Anybody
can help me how to do this? Many thanks!

Lei Tang
email: leitang@sprynet.com




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

Date: Sat, 6 Feb 1999 22:17:47 -0500
From: "Allan M. Due" <allan@due.net>
Subject: Re: Help: How to trim the blanks of a string at the beginning and the end.
Message-Id: <yB7v2.671$L1.13839@nntp1.nac.net>

LEI TANG wrote in message <79itif$n3j$1@juliana.sprynet.com>...
:I want to trim the blanks at the beginning and the end of a string, and also
:replace the blanks with only one blank in the middle of the string. Anybody
:can help me how to do this? Many thanks!


Around these parts we usually post wee bit of code that we tried but didn't
work so that others can point us on the road to rightousness.  Correction
often is more edifying than demonstration.  All that being said here is a
pedantic illustratioin to get you started.  Of course, you must always
remember the Perl moto.

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

my $string = '     foo     bar      ';
print "[$string]\n";
$string =~ s/^\s*//;
print "[$string]\n";
$string =~ s/\s*$//;
print "[$string]\n";
$string =~ s/\s+/ /;
print "[$string]\n";

HTH

AmD






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

Date: Sat, 6 Feb 1999 22:38:00 -0500
From: "Allan M. Due" <allan@due.net>
Subject: Re: Help: How to trim the blanks of a string at the beginning and the end.
Message-Id: <yU7v2.675$L1.13814@nntp1.nac.net>

Allan M. Due wrote in message ...
:LEI TANG wrote in message <79itif$n3j$1@juliana.sprynet.com>...
::I want to trim the blanks at the beginning and the end of a string, and also
::replace the blanks with only one blank in the middle of the string. Anybody
::can help me how to do this? Many thanks!
:
:Around these parts we usually post wee bit of code that we tried but didn't
:work so that others can point us on the road to rightousness.  Correction
:often is more edifying than demonstration.  All that being said here is a
:pedantic illustratioin to get you started.  Of course, you must always
:remember the Perl moto.
:#!/usr/local/bin/perl -w
:use strict;
:my $string = '     foo     bar      ';
:print "[$string]\n";
:$string =~ s/^\s*//;
:print "[$string]\n";
:$string =~ s/\s*$//;
:print "[$string]\n";
:$string =~ s/\s+/ /;
:print "[$string]\n";


Looking at my post I realize that those * should be + (no reason to replace
nothing with nothing) and that I should already be in bed.  Ah well.

AmD





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

Date: Sat, 06 Feb 1999 21:52:37 -0700
From: ekihn <ekihn@bewellnet.com>
Subject: Java/Perl Lingo.
Message-Id: <36BD1C15.A256DAD0@bewellnet.com>

Greetings,

	I read with excitement on perl.com that JPL had gone open soure and I
would now be able to freely incorporate
PERL in my Java GUI wrappers. The announcement was Dec 6th and I'm still
not have much luck finding perl packages/source out there. Apologies if
this is an FAQ but where can I get the code?

Eric Kihn
kihn@mindspring.com


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

Date: Sat, 06 Feb 1999 22:52:43 -0800
From: dan <nospam-seallama@mailcity.com>
Subject: keeping track of members logged in
Message-Id: <36BD383A.FE488B74@mailcity.com>

lets say someone comes to my site, and logs in.  the value is added to a
logfile.  ill use javascript to automatically submit a form when the
user closes the window. the form will contain a hidden field that has
the user's name.  how do i search the logfile for the name and then
delete it from the file? thanks




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

Date: Sun, 07 Feb 1999 07:51:40 +0000
From: Paul Williams <paul@rainbow.nwnet.co.uk>
To: dan <nospam-seallama@mailcity.com>
Subject: Re: keeping track of members logged in
Message-Id: <36BD460C.20E012FD@rainbow.nwnet.co.uk>

Simple way to delete old data from a file and re add new data... You
might need to mess around with the code but its a start for you...


--- snip ---

#!/usr/bin/perl
# assuming info is set on one line like - username:time()
#
# jim 918373205
# susan 918373205
#

# Set by you, just here for posterity
$username = "sammy";

open(FILE, "database.txt") || die "$!";
@lines = <FILE>;
close(FILE);

open(WRITE, ">database.txt") || die "$!";
foreach (@lines)
{
	if (/$username/)
	{
		# This will add the updated data, comment it out if you
		# don't want to print the username again.
		print WRITE "$username " . time;

		# Next basically skips writing the data
		next;
	}
	print WRITE;
}
close(WRITE);

# Done !

--- snip ---

dan wrote:
> 
> lets say someone comes to my site, and logs in.  the value is added to a
> logfile.  ill use javascript to automatically submit a form when the
> user closes the window. the form will contain a hidden field that has
> the user's name.  how do i search the logfile for the name and then
> delete it from the file? thanks


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

Date: Sun, 07 Feb 1999 01:16:20 -0500
From: "John T. Jarrett" <jjarrett@ecpi.com>
Subject: newbie: Perl Book (Cookbook)
Message-Id: <36BD2FB2.E570BDD5@ecpi.com>

Perl Cookbook, Tom Christiansen & Nathan Torkington, O'Reilly &
Associates

Web programming in Perl is kind of funny: the CGI newsgroup aren't
programmers and the perl ng is perl programmers - no real in between. So
I've stayed around both, helped with a few purely perl but CGI questions
for real beginners and hopefully learned a thing or tow.

But the problems I've had, well, basically made me look like an idiot.
Other people's servers; either no telnet access at all or everything is
in the wrong directories (and you run Find and, wham!, four thousand
websites you don't have access to and somewhere in there is maybe the
one line you wanted...). Telnet access with a five second delay (or
more!). I couldn't load modules (no access to lib directories), I
couldn't make them in my own dir (you don't have permission to use
make!), the only data for putting modules in your own dir is 'try man
ExtUtils::MakeMaker' - yeah, try 'no man page entry' ! Arggh!

So, two months later, I broke down and spent an hour at Bookstop. Let me
tell you, I think the best book for guys 'that know some programming' or
sysadmin or something - basically, that aren't complete idiots - the
best perl book is PERL COOKBOOK by, duh, O'Reilly. It may not come with
a CD, but all the source code files are available online in one big
(179k) zip file!

Thanks, Tom (& Nathan).

One thing, though. You know Master Tom Christiansen is here, available,
as are most of the O'Reilly Perl authors -- would you really go with a
Que book because it is bigger and has a CD?

Forget it. This book gave me a one-liner to find where the
already-installed modules are on any system (no matter what weird dir)
AND it gave me a prewritten program that will list out all installed
modules and what they do!

And it is still over 700 pages. Excellent book.

John



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

Date: Sat, 6 Feb 1999 22:35:54 -0600
From: "Glen Lee Edwards" <GLEdwards@christianfamilies.net>
Subject: No such file or directory
Message-Id: <79j503$avu2@iac7.navix.net>

I'm trying to install a Perl script on a Linux system and on three of the
cgi scripts I keep getting a "no such file or directory" error.  But when I
look through the script it appears that the syntax referencing the files are
correct, and all the respective folders are in place.  Any suggestion?

Thanks,

Glen




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

Date: 7 Feb 1999 02:53:20 GMT
From: Xeno Campanoli <xeno@bigger.aa.net>
Subject: Re: Perl5.005002 Broken on number passing?
Message-Id: <79iv70$9rg$1@slave3.aa.net>

Larry Rosler <lr@hpl.hp.com> wrote:
: [Posted and a courtesy copy mailed.]

: In article <79fgb9$t1q$1@slave1.aa.net> on 5 Feb 1999 19:21:13 GMT, Xeno 
: Campanoli <xeno@bigger.aa.net> says...
:> I've got the following:
:> 
:> $n = 005.5;
:> 
:> I then print
:> 
:> print STDERR "trace $n\n";
:> 
:> I get back:
:> 
:> trace 55
:> 
:> You can't tell me that this isn't broken.  Larry, you've gotta fix this
:> fast!!  Sincerely, Xeno
:> 
:> P.S., a quick fix is $n = "005.5" instead.

: Let (Just Another Larry) tell you that this isn't broken!  '005.5' isn't 
: a valid floating-point number, as you assume.  It is being parsed as the 
: concatenation of two numeric literals converted to strings:

:   ('005' becomes (octal) 5 becomes '5') . (5 becomes '5')

Okay.  I get it.  That makes sense, but, well, I wish it didn't have to
work that way.  Thanks.

Xeno Campanoli
Email:	xeno@aa.net	(Web pages:  http://www.aa.net/~xeno)


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

Date: 7 Feb 1999 04:31:40 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Perl5.005002 Broken on number passing?
Message-Id: <918361897.549652@elaine.drink.com>

In article <MPG.1124ef82ed4d49af989a0c@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>This is not a 5.005_02 problem, as your Subject suggests.  I have 
>confirmed this behavior as far bask as 5.002.

I see your 5.002 and raise you a 1.010

#!/usr/bin/perl1.010 

$a=005.5
print $a,"\n";

gives 55


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

Date: Sat, 06 Feb 1999 17:02:33 -0600
From: Dan Kisting <dkisting@cc.edu>
Subject: Please Help Quickly
Message-Id: <36BCCA09.8D639C95@cc.edu>

My boss at my company gave me a project to do, which normally would not
be a problem. I could do it in either JavaScript or ASP and there would
not be a problem.  Except it is on a UNIX server and it has to be server

side.  He wants me to use PERL to do it, but I have no background with
it.

We need to figure out site space for each site hosting purpose.
Now we have a manual system whenever we need the numbers.
System needs to be automated and available (password protected)
The basis for the project is as follows:
We need to figure out site space for each client for site hosting
purpose.
They need to get site MB numbers anytime. The task scope will
be:
 After you choose one of the client from above client drop-down box, the

second page with week number and the site directory list will show up.
The
week number should be dynamically generated as a drop-down box with
current
week selected. The current week can be calculated with Javascript. The
week
number should be from week01, week02,...,week53. The directory list
should
be dynamically generated from the same configuration file located in
/www/sitesize/conf/sitesize.conf. The directory list should be in texa
area
so that it can be add or delete from the text area.
3. After you click on the submit, the site size information should be
generated with details like this (use table format):

>Week: week05
>Date: 05-FEB-1999
>Site URL: www.o.com MB
>Site size: /www/kohler 900
> /www/logs 1000
>Total: 1900
>
>Email: (text field for email address)
>
>This page should be a form so that anyone can fill out his/her email
>address and receive it after submit.
>
>4. After you click on submit, the site size information (with table
format
>like above) should be send out and will be saved in the current week
>directory. The week directory will be
>/www/sitesize/numbers/1999/www.o.com/week#. The week# comes from the
>form and the week# directory should be dynamically created when you
click
>submit. The saved file format will be different from the email message.
The
>data format should be easy for people to input into Excel spread sheet.
So
>the format should be something like:
>
>
>When you save the data, check the directory first to see if the
directory
>existed or not. If it exists, just generated a sorry message to let
person
>know.


Any Help for guy who is lost??



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

Date: 7 Feb 1999 03:47:59 GMT
From: pjk6@po.cwru.edu (Peter J. Kernan)
Subject: Re: Program needs compactification
Message-Id: <79j2df$ltm$1@pale-rider.INS.CWRU.Edu>

In article <x7iudfm86w.fsf@home.sysarch.com>,
	Uri Guttman <uri@home.sysarch.com> writes:
>>>>>> "MJTG" == M J T Guy <mjtg@cus.cam.ac.uk> writes:
> 
> MJTG> I suspect you don't understand that [@F,,@F] is the same as 
>      [@F,@F].
my braino. (among others)
> 
[..snip...]
>  perl -la0777ne 'print for keys %{{@F,("")x((@F&1)^1),@F}}'
> 
> that works but you will get a null word if @F is even. and it is very
> ugly. maybe there is a better way to get a "" if @F is even.
> 
> this is slightly cleaner but ugly nonetheless.
> 
> perl -la0777ne 'print for keys %{{@F,(@F&1?():""),@F}}'

another way: 'print for sort keys %{{(@F,@F%2?@F:pop @F)x2}}'

no null
> 
> 
> my previous solution is much more elegant:
> 
> perl -la0777ne '@a{@F}=();print for sort keys %a'
> 
agreed. what i attempted to do and failed to understand that 
i was failing to do was to somehow stick the @a{@F} initialization
step into the anonymous hash. I dont know if it is possible, perhaps
not. Thanks all.

ps. one can lose another char above with @a{@F}++;

-- 
             I must be cruel, only to be kind; --Hamlet


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

Date: 06 Feb 1999 23:49:43 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Program needs compactification
Message-Id: <x7g18in7h4.fsf@home.sysarch.com>

>>>>> "PJK" == Peter J Kernan <pjk6@po.cwru.edu> writes:

  >> this is slightly cleaner but ugly nonetheless.
  >> 
  >> perl -la0777ne 'print for keys %{{@F,(@F&1?():""),@F}}'

  PJK> another way: 'print for sort keys %{{(@F,@F%2?@F:pop @F)x2}}'

  PJK> no null

and the ugliest code so far. :-)

  PJK> ps. one can lose another char above with @a{@F}++;

that is strange looking but it seems to work. it only increments one
hash element (the last in @F) and it sets the rest to undef. it makes
sense as it is evaluating the hash slice in a scalar context (++) and
therefore doing the comma operator. at least that is my understanding.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Sat, 6 Feb 1999 22:02:37 -0500
From: "DMDP" <dmdp@miracle.net>
Subject: Redirecting STDOUT
Message-Id: <79ivpb$jsf$1@roadrunner.micro-net.net>

I have a script that is executing system call.

I need to output of the system call to send its output to a file.

I have done the following:

#!/usr/bin/perl

-print some sutff here

close(STDOUT);

open(STDOUT,">out.txt");
select(STDOUT); $| =1;
system(  );
close(STDOUT);

open(STDOUT,">&SAVEOUT");

Anyone have any thoughts on this?

Thanks in Advance,
Denis dePierro




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

Date: 06 Feb 1999 20:55:01 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Redirecting STDOUT
Message-Id: <yllniax17e.fsf@windlord.stanford.edu>

DMDP <dmdp@miracle.net> writes:

> I have a script that is executing system call.  I need to output of the
> system call to send its output to a file.  I have done the following:

[...]
> close(STDOUT);

> open(STDOUT,">out.txt");
> select(STDOUT); $| =1;
> system(  );
> close(STDOUT);

> open(STDOUT,">&SAVEOUT");

> Anyone have any thoughts on this?

Yes.  It works fine; I do it all the time.  It's even documented in the
perlfunc man page under open.

Note that there at least used to be some oddities involving closing
*STDERR* and then calling die.  I'm not sure if they've been fixed yet.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sat, 6 Feb 1999 23:31:59 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: regex - matching acros lines
Message-Id: <1dmtvpt.n5do4dlu07puN@bay1-346.quincy.ziplink.net>

Eric Smith <eric@fruitcom.com> wrote:

> $_ =~ s/%SH%[\n.]*?%EH%//g; and $_ =~ s/%SH%[\n.]*?%EH%//s;

[.] matches a literal period.  '.' is not special in a character class.

What you really want is something like this:

$_ =~ s/%SH%.*?%EH%//gs;

Normally '.' matches everything but newline; the /s makes it match
newlines too.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 6 Feb 1999 23:32:01 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: What's happening with this hash?
Message-Id: <1dmtvtz.1swnf761rfegxtN@bay1-346.quincy.ziplink.net>

John Moreno <phenix@interpath.com> wrote:

> > You have one named hash, %fruit, and two anonymous hashes.  There are no
> > hashes with the name of the key, whatever that means.  :-)
> 
> 
> I've got a hash with keys from 1 to 10, I thought I was creating hashes
> with names like %1, %2, %3 and so forth with the 
> 
> $hash{$i}{'test'}++
> 
> each hash only having only one element.

Ah...  but the keys are used only as keys.  It's the values that you can
use as symbolic refs.

So, since you had a hash with keys from 1 to 10, and the value for each
key was 1, you were creating a single hash with the name %1, and
incrementing the value of $1{'test'} with

$hash{$i}{'test'}++


> With $$hash{$i}{'test'}++ I seem to be getting result I expected, but
> obviously not in the way I intended.
> 
> I believe I understand it better now -- the $$hash is creating a
> variable named $hash and putting a reference to a anonymous hash in it?

Exactly.

> The value of each key in that hash is yet another hash -- each with a
> key of 'test' and whatever value I put into it.

Right again.

> I could get the same end results of that script if I dropped the
> {'test'} completely and just used $$hash{$i} to hold the end value.

Yes, that would have worked too.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sun, 7 Feb 1999 01:12:34 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: What's happening with this hash?
Message-Id: <1dmtzag.1apyrsp1gtdtojN@roxboro0-029.dyn.interpath.net>

Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:

> John Moreno <phenix@interpath.com> wrote:
> 
-snip-
> 
> Exactly.
> 
-snip-
> Right again.
-snip-
> Yes, that would have worked too.

So hashes still aren't my strong suit but I understand it a bit better.

Thanks for the help.

-- 
John Moreno


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

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

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