[7345] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 970 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 3 18:17:20 1997

Date: Wed, 3 Sep 97 15:00:43 -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           Wed, 3 Sep 1997     Volume: 8 Number: 970

Today's topics:
     Re: "Odd number of elements in hash list": So? <rootbeer@teleport.com>
     100% Pure Java Meta Search Engine? <alastair@net7.co.uk>
     Re: Can Perl call external programs? <rootbeer@teleport.com>
     Re: Can Perl call external programs? <helgek@berlin.snafu.de>
     Re: Handling complex table files <stefano.bonacina@st.com>
     Re: Help! cron&perl ! (I R A Aggie)
     Re: Is Perl for Win32 really as brain damaged as it see <rootbeer@teleport.com>
     Re: Is Perl for Win32 really as brain damaged as it see (Kevin)
     Re: IS there a 'strlen' in Perl? (SJK)
     Re: mktime bug on Perl5.004 Solaris 2.5 (Ronald L. Parker)
     Re: Newbie File Locking <rootbeer@teleport.com>
     Re: Newbie File Locking (Andrew M. Langmead)
     Numeric sorting <chambers_t@svhdev.bt.co.uk>
     Re: Numeric sorting (brian d foy)
     Re: Numeric sorting <mark@tstonramp.com>
     Re: pattern matching HELP! <rootbeer@teleport.com>
     Re: Patternmatching with arrays <mark@tstonramp.com>
     Re: perl and XEmacs (Chris Nandor)
     Re: perl and XEmacs (I R A Aggie)
     Re: perl and XEmacs (Gary D. Foster)
     Re: Printing two variables on alternate lines? <mark@tstonramp.com>
     Putting function names in variables (Tracy Bednar)
     Re: Q: assoc. arrays as subroutine argument <rootbeer@teleport.com>
     Re: Query Strings & CGI's <rootbeer@teleport.com>
     question about perlembed <jinyu@cs.sunysb.edu>
     Should you close files (was: Re: Pattern Matching with  <rootbeer@teleport.com>
     Re: Simple Perl for  Win 32 Question (not in FAQ) (Ronald L. Parker)
     Re: Telnet Parameters?  Please Help! <lwp@flenser.att.net>
     Re: Who is still interested in SOCKS? <kermit@ticnet.com>
     Re: WHY doesnt this work ?? <rootbeer@teleport.com>
     Re: WHY doesnt this work ?? (I R A Aggie)
     Re: WHY doesnt this work ?? <doug@ono.tc.net>
     Win32/ Perl -S (pl2bat) <axel@apl.washington.edu>
     Re: Wrote new module, need help with system dependencie <vladimir@cs.ualberta.ca>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 3 Sep 1997 12:16:45 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: doug_claar@hp.cNoSPAm
Subject: Re: "Odd number of elements in hash list": So?
Message-Id: <Pine.GSO.3.96.970903121328.11990I-100000@julie.teleport.com>

On 3 Sep 1997, Doug Claar wrote:

> With -w and strict turned on, perl 5.004 warns me that I have an
> "Odd number of elements in hash list". Why does it care, and should
> I care? Seems like a fairly useless error message, in that--if there
> is a reason that this is bad, it certainly doesn't tell you what it
> is, and if it isn't, why print it?

Error messages, by their nature, can't include much in the way of
explanation. But that's why the perldiag(1) manpage was created, to give
you more details. It says:

    =item Odd number of elements in hash list

    (S) You specified an odd number of elements to a hash list, which is
    odd, because hash lists come in key/value pairs. 

To me, this says it all. But just to be sure it's clear, it means that you
had a key without a value, which almost always means that you did
something wrong in your code. And _that_ is the reason that Perl is
nagging you, so that it can help you to find your bugs. 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 Sep 1997 21:34:43 +0100
From: Alastair Todd <alastair@net7.co.uk>
Subject: 100% Pure Java Meta Search Engine?
Message-Id: <340DC9E3.F294C1AF@net7.co.uk>

dataTRAK - Java Meta-Search Engine:
http://www.net7.co.uk/dataTRAK/Trakker.htm

Its Free!

If you've got NS4.0 or IE3.02+ this is just what you need.

Sorry if this seems like a spam, but I'm honestly not selling anything -
I just think you should use it that's all.

+ Are you not intrigued as to why you need NS4.0 or IE3.02+? There has
not been anything like that since NS2.0 first supported Java.

Sincerely,

--
Alastair R. Todd,
System's Development Manager,
Net7 Limited
http://www.net7.co.uk/






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

Date: Wed, 3 Sep 1997 12:42:43 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Kenny Owens <kowens@stride.doe.gov>
Subject: Re: Can Perl call external programs?
Message-Id: <Pine.GSO.3.96.970903123932.11990L-100000@julie.teleport.com>

On Wed, 3 Sep 1997, Kenny Owens wrote:

> Can Perl call an external program besides C?  

Yes. In fact, when Perl calls an external program, it doesn't normally
know or care what language the other program is written in. See system and
open in the perlfunc(1) manpage, or qx// in the perlop(1) manpage. There's
More Than One Way To Do It. Have fun!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 3 Sep 1997 20:02:28 GMT
From: "Helge Kruse" <helgek@berlin.snafu.de>
Subject: Re: Can Perl call external programs?
Message-Id: <01bcb8a4$e1f7ec00$37e0c3c2@hk.bercos.berkom.de>



Kenny Owens <kowens@stride.doe.gov> schrieb im Beitrag
<340DAEA9.3F2E@stride.doe.gov>...
> 
> Can Perl call external programs besides c??  I need to call a FoxPro
> program from within Perl and pass some parameters.  Can this be done? 
> Do I need to do anything "special" to handle the parameters or the
> FoxPro program?  
If you want to wait that the external program terminates,
just try:

system("/who/to/start/foxpro  with theese parameters");

If you want a background process, you can look at fork and execute.

Helge



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

Date: Tue, 02 Sep 1997 13:58:16 +0200
From: stefano bonacina <stefano.bonacina@st.com>
Subject: Re: Handling complex table files
Message-Id: <340BFF58.228F@st.com>

stefano bonacina wrote:
> 
> Hello all
> I have a file with a similar structure:
> 
> name  label             type                          default unit
> words {Number of words} {range int 64 32768}           64      {}
> bits  {Number of bits}  {range int 2 64}               2       {}
> mux   {Mux size}        {enum int {4 8 16 32}}         4       {}
> 
> Separators are blank space, not tab (too easy :-).
> Does anyone know any clever way to handle these lines assigning to
> different variables the content of each fields? (I'm using perl 5.004)
> Thanks in advance for your help
> --
> Stefano Bonacina                E-mail: stefano.bonacina@st.com
> SGS-Thomson Microelectronics

Happiness!
I discovered it.
Here's the stupid perl code to split the above lines:

open(FILE,"complex_table");
while (<FILE>) {
    	($param,$desc,$range,$default,$unit) = ($_ =~
/^\s+(\S+)\s+{(.*)}\s+{(.*)}\s+(\S+)\s+(\S+)/);
	#	
	# and now we print the result
	#    	
	print $param," ",$desc," ",$range," ",$default," ",$unit,"\n";

}
close(FILE);

regards

-- 
Stefano Bonacina		E-mail:	stefano.bonacina@st.com
SGS-Thomson Microelectronics


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

Date: Wed, 03 Sep 1997 16:28:09 -0400
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: Help! cron&perl !
Message-Id: <fl_aggie-ya02408000R0309971628090001@news.fsu.edu>


In article <5uisn2$hir$1@oravannahka.Helsinki.FI>, Tero Tuononen
<tuononen@cc.helsinki.fi> wrote:

+ All
+ the stuff is located in the same directory but is there still a problem
+ with paths or what ? 

Yes. Always assume that cron-jobs have a limited path and environment.

James

-- 
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: Wed, 3 Sep 1997 12:59:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jessica <jdm@thetics.europa.com>
Subject: Re: Is Perl for Win32 really as brain damaged as it seems?
Message-Id: <Pine.GSO.3.96.970903125057.11990O-100000@julie.teleport.com>

On 3 Sep 1997, Jessica wrote:

> Subject: Is Perl for Win32 really as brain damaged as it seems?

That's quite possible. :-)

> I tried using backticks to execute the command and it would run the
> command correctly and return the correct output to my script, but for no
> apparent reason, _it would access a:\ every time the external command
> was executed_.  The external command doesn't reference a:\ and nothing
> in my path or environment references a:\.  This made the drive grind
> noisily throughout the entire operation and was rather irritating to
> listen to. 

I've heard of this from other people, but (lacking a Win32 machine) I
haven't seen it myself. Just lucky, I guess. :-)

(Speculation alert.) I _think_ that a command in backticks is (sometimes?) 
handed off to the command-line processor, COMMAND.COM, which may be the
culprit here. (But I don't know why _anything_ should be running the
floppy drive here.) Does this happen with Sarathy's most recent binary?

    http://www.perl.com/CPAN/authors/id/GSAR/

> Also, chdir and Win32::SetCwd do not work when attempting to change
> the current directory to a different drive and using opendir on the
> root of a drive fails.

Sounds like you're ready to file a bug report. :-)

Good luck with it!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 3 Sep 1997 13:44:00 -0700
From: klander@primenet (Kevin)
Subject: Re: Is Perl for Win32 really as brain damaged as it seems?
Message-Id: <340dc7fc.15344624@news.primenet.com>

On 3 Sep 1997 17:31:37 GMT, jdm@thetics.europa.com (Jessica) wrote:

>
>I'm attempting to write a script to run an external command for every
>file in a directory tree under Win95 and WinNT and presents the results.
>
>I tried using backticks to execute the command and it would run the 
>command correctly and return the correct output to my script, but for
>no apparent reason, _it would access a:\ every time the external command
>was executed_.  The external command doesn't reference a:\ and nothing
>in my path or environment references a:\.  This made the drive grind
>noisily throughout the entire operation and was rather irritating to
>listen to.  just the command print `dir c:\`; by itself accesses my
>floppy drive for no reason.  This happens with both builds 110 and 307 
>and when I mentioned it to a coworker, he claimed to have seen this 
>problem before also.
>

Hmm...never heard of that one.  I just ran this little test script and
it works fine.  See if it causes the problem your talking about.  If
so, you may have a problem with your installation.  I'm running
WinNT.40 and perl5.003_07 (build 307).

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

@ls = <*>;

foreach $filename (@ls) {
   $outp = `type $filename` if (! -B $filename);
   print "$outp" if ($outp);
}

exit;

If this doesn't cause the problem, let's see an example of one that
does.

For what it's worth, I also ran

perl -e "print `dir c:\\ `"

and it ran without accessing a:\.

--
  Kevin -- klander at primenet dot com (add the .com in email replies)
           http://www.primenet.com/~klander
--


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

Date: Wed, 03 Sep 1997 19:19:42 GMT
From: knetsch@golden.net.no.spam (SJK)
Subject: Re: IS there a 'strlen' in Perl?
Message-Id: <340db826.9952328@news.golden.net>

On 3 Sep 1997 16:31:53 GMT, jzhuang@ringer.cs.utsa.edu (Jun Zhuang) wrote:

>Is there a function like 'strlen()' in C in Perl5?
>I just want to use it to count the chars in a char string.
>
>--


Ummm......  $lengthofline = length($myline) ?????

SK

Stuart Knetsch

Remove the you know what from my address to send me E-mail


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

Date: Wed, 03 Sep 1997 20:42:58 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Re: mktime bug on Perl5.004 Solaris 2.5
Message-Id: <340eabb8.6551172@news.supernews.com>

On Tue, 02 Sep 1997 22:41:56 -0600, scott@excite.com wrote:

>I seem to be having problems with times, even after switching to
>POSIX::mktime
>
>Any ideas, patches or workarounds? The C version of mktime seems to work
>fine.
>
>Scott
>
> ./timelocal.pl
>time = 873248400 -> Sun, Sep 02 1997  9:00PM EST -> mktime = 873252000
>time = 873248400 -> Sun, Sep 03 1997  1:00AM GMT -> mktime = 873248400

The problem is that your time zone is not EST, it's EDT.  You're
ignoring the very useful $isdst flag that is returned by localtime.
strftime and mktime both accept it as the last parameter in the list
(don't forget the two intervening zeros for $wday and $yday) and it is
necessary if you want correct results, unless you're lucky enough to
live where there is no DST or you only run your program in the winter.

Sunday, September 2, 1997 9:00 PM EST really is 873252000.  But 
873248400 is Sunday, September 2, 1997 9:00 PM _EDT_ (8:00 PM EST).

--
Ron Parker
Software Engineer
Farm Works Software       Come see us at http://www.farmworks.com
For PGP public key see http://www.farmworks.com/Ron_Parker_PGP_key.txt


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

Date: Wed, 3 Sep 1997 11:59:15 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Martin Fischer <mf@fishbone.ruhr.de>
Subject: Re: Newbie File Locking
Message-Id: <Pine.GSO.3.96.970903115241.11990G-100000@julie.teleport.com>

On 3 Sep 1997, Martin Fischer wrote: 

> flock FILE, 8;  # not really needed, perl does it on closing the file
> close FILE; 

Not only is it not really needed, it's also not really recommended, not
really good, and not really safe! :-)

At the moment just after you release the lock, another program will get
the chance to write to the file. But you may (and usually do) have data in
a buffer in memory which has not been written to the file yet. That means
that the file may be incomplete, but the other script now has permission
to start working with it. Eek!

The solution is to never, never, never release the lock on the file. (This
rule can be disregarded by fools and experts, but by no one in between. 
:-)  When you close the filehandle (or simply end your process) the buffer
will always be flushed properly before the lock is released. It's simpler,
safer, and cleaner. 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 3 Sep 1997 19:00:43 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Newbie File Locking
Message-Id: <EFy4t7.Hwy@world.std.com>

Martin Fischer <mf@fishbone.ruhr.de> writes:

>flock FILE, 8;  # not really needed, perl does it on closing the file

You better off skipping this. If your script has any data buffered but
not written, you are unlocking too soon. (You script will flush the
buffer and writer to the file after the lock was released.)Just close
the file and let the kernel take care of closing the file and
releasing the lock as one atomic operation. (Perl doesn't do the
unlocking, its the kernel.)

One source of example code using flock is <URL:http://www.stonehenge.com/
merlyn/WebTechniques/col04.html>
-- 
Andrew Langmead


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

Date: Wed, 03 Sep 1997 19:59:48 +0100
From: Trevor Chambers <chambers_t@svhdev.bt.co.uk>
Subject: Numeric sorting
Message-Id: <340DB3A4.3418@svhdev.bt.co.uk>

I have a file along the lines of

name1 1
name2 31
name3 7
name4 2

etc, and I want to sort it into descending numerical order....but I'm
stuck.  I presently read the file in to an associative array, and then
tried to sort by the values, but couldn't make it work.

I tried using backticks and the Unix sort, but I couldn't make that work
properly either...it sees 31 as lower than 7 (3<7).

This must be really common and simple...could someone enlighten me?

Thanks in advance....

Trevor
chambetm@boat.bt.com


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

Date: Wed, 03 Sep 1997 15:52:43 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Numeric sorting
Message-Id: <comdog-ya02408000R0309971552430001@news.panix.com>

In article <340DB3A4.3418@svhdev.bt.co.uk>, Trevor Chambers <chambers_t@svhdev.bt.co.uk> wrote:

>I have a file along the lines of
>
>name1 1
>name2 31
>name3 7
>name4 2
>
>etc, and I want to sort it into descending numerical order....but I'm
>stuck.  I presently read the file in to an associative array, and then
>tried to sort by the values, but couldn't make it work.

you might want to check out "Advanced Sorting" in chapter 15 of 
the new Learning Perl [1] for more examples:

#!/usr/bin/perl

# make our hash
%hash = qw( name1 1 
            name2 31 
            name3 7 
            name4 2);

# sort in descending order by comparing the numeric values
# of the hash using the spaceship operator
foreach( sort { $hash{$b} <=> $hash{$a} } keys %hash )
   {
   print "$_: $hash{$_}\n";
   }

__END__

name2: 31
name3: 7
name4: 2
name1: 1


good luck :)

[1]
Learning Perl
Randal L. Schwartz & Tom Christensen
ISBN 1-56592-284-0. 
<URL:http://www.ora.com>

-- 
brian d foy                                  <comdog@computerdog.com>


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

Date: Wed, 03 Sep 1997 01:49:42 -0700
From: "Mark J. Schaal" <mark@tstonramp.com>
Subject: Re: Numeric sorting
Message-Id: <340D24A6.D22@tstonramp.com>

Trevor Chambers wrote:
> 
> I have a file along the lines of
> 
> name1 1
> name2 31
> name3 7
> name4 2
> 
> etc, and I want to sort it into descending numerical order....but I'm
> stuck.  I presently read the file in to an associative array, and then
> tried to sort by the values, but couldn't make it work.
> 
> I tried using backticks and the Unix sort, but I couldn't make that work
> properly either...it sees 31 as lower than 7 (3<7).
> 

By default both Perl and Unix sort sort in alphabetical order. 
I saw another response showing a Perl solution, so I'll just 
mention the /bin/sort solutions.  One (or both) of the following
should work, depending upon your platform.  It should be documented
in the sort man page.
  sort -n +1 infile > outfile
  sort -k 2n infile > outfile

Hope this helps!

mark
--
Mark J. Schaal		TST On Ramp Sysadm	mark@tstonramp.com


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

Date: Wed, 3 Sep 1997 12:44:41 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: pattern matching HELP!
Message-Id: <Pine.GSO.3.96.970903124325.11990M-100000@julie.teleport.com>

On Wed, 3 Sep 1997, Eric Bohlman wrote:

> : die "foo'ed\n" unless ($bob =~ /^[a-z0-9_&\.-]*$/);
> 
> Nope.  That pattern will match *any* string (start of string, followed by
> *zero or more* characters in the class, followed by end of string). 

That's not *any* string. Thanks for trying!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 Sep 1997 01:36:05 -0700
From: "Mark J. Schaal" <mark@tstonramp.com>
Subject: Re: Patternmatching with arrays
Message-Id: <340D2175.35CD@tstonramp.com>

Robert wrote:
> 
> 
> Hi, I'm very new to perl and have this problem.
> I'm trying to do a script that takes a file (OLD) reads in to an
> array, then if a line exists in that file I want it to display the
> html. I'm sure this is a very easy thing, but I just can't get it to
> work!
> 
> This is a the piece of the code that's the problem
> 
> open (OLD, "$REAL") || die ("couldnt open file for reading");
> @search_array = <OLD>;

This reads the whole file OLD into @search_array.


>     while (<OLD>) {

This would read the file OLD line by line, putting the line
into $_, but since you already read the whole file it does
nothing and never enter the while loop.  Probably what you want
is to remove the @search_array = <OLD>; line and change the
above to 
	while ($search_array = <OLD>) {


>    if ($search_array =~ "/<!-- $TIME $ROOM --!>/\n") {
> 
> print "content-type: text/html\n\n";
>  print "<html><head><title>Occupied</title></head>\n";
>  print "<body bgcolor=#ffcc99><center><font size=5 color=Maroon>Room
> is already occupied</font>\n";
>   print "</center></body></html>";
> 
>  close (OLD);   }
> }


Hope this helps!

mark
--
Mark J. Schaal		TST On Ramp Sysadm	mark@tstonramp.com


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

Date: Wed, 03 Sep 1997 15:04:52 -0400
From: pudge@pobox.com (Chris Nandor)
Subject: Re: perl and XEmacs
Message-Id: <pudge-ya02408000R0309971504520001@news.idt.net>

In article <bcioh6ab6l1.fsf@corp.Sun.COM>, Gary.Foster@corp.Sun.COM (Gary
D. Foster) wrote:

# From this we learn a very simple lesson... Lisp is the language of
# purity and faith.  Perl is for nazi's and oppresion.  Never forgive,
# never forget.  Keep the faith.

I know this was all supposed to be humourous, but it wasn't particularly funny.

--
Chris Nandor             pudge@pobox.com             http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])


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

Date: Wed, 03 Sep 1997 16:31:02 -0400
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: perl and XEmacs
Message-Id: <fl_aggie-ya02408000R0309971631020001@news.fsu.edu>


In article <bcioh6ab6l1.fsf@corp.Sun.COM>, Gary.Foster@corp.Sun.COM (Gary
D. Foster) wrote:

[an attempt to invoke Godwin's law]

+ Perl was constructed by Hitler as a means to bring the Nazi party into
+ power.

[deletia]

+ It's a little known fact, however, that the Jewish people, in an
+ effort to keep their faith and their bloodlines pure, adapted the
+ "Common Lisp" currently in use by the peasantry into a secret idiom,
+ referred to in kabbalistic circles as "Emacs Lisp".

So, you're saying that I really really piss off YVHW every time I invoke
emacs to do perl?

James

-- 
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: 03 Sep 1997 13:36:42 -0700
From: Gary.Foster@corp.Sun.COM (Gary D. Foster)
Subject: Re: perl and XEmacs
Message-Id: <bcilo1ecexx.fsf@corp.Sun.COM>

>>>>> "Chris" == Chris Nandor <pudge@pobox.com> writes:

    Chris> I know this was all supposed to be humourous, but it wasn't
    Chris> particularly funny.

Depends on your sense of humor, now doesn't it?  Perhaps you might
have said "wasn't particularly funny _to me_", if you really want to
be pedantic about it.

-- Gary F.


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

Date: Wed, 03 Sep 1997 01:26:12 -0700
From: "Mark J. Schaal" <mark@tstonramp.com>
Subject: Re: Printing two variables on alternate lines?
Message-Id: <340D1F24.233F@tstonramp.com>

Phil Davey wrote:
> I have two variables containing multiple line text and I would like to
> print them on alternate lines.
> 
> For example if $foo is:
> xxxxxxxxxxxxxxxxxx
> xxxxxxxxxxxxxxxxxx
> 
> and $bar is:
> aaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaa
> 
> I would like to end up with:
> xxxxxxxxxxxxxxxxxx
> aaaaaaaaaaaaaaaaaa
> xxxxxxxxxxxxxxxxxx
> aaaaaaaaaaaaaaaaaa
> 

Something like the following?  You could also do it with
index() and substr() and avoid the temporary arrays.

$foo = "xxxx\nxxxx";
$bar = "aaaa\naaaa";

@foo = split(/\n/, $foo);
@bar = split(/\n/, $bar);

for ($i=0; $i < @foo; $i++) {
  print "$foo[$i]\n$bar[$i]\n";
}



hope this helps!

mark
--
Mark J. Schaal		TST On Ramp Sysadm	mark@tstonramp.com


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

Date: Wed, 3 Sep 1997 20:18:17 GMT
From: spectran@netcom.com (Tracy Bednar)
Subject: Putting function names in variables
Message-Id: <spectranEFy8EH.Kut@netcom.com>


Is it possible to put function names in a variable, then call the function
by referencing the variable?

ex:

$func = "print";
$func "Hello World\n";


I've tried this , and the eval statement, but with no luck.
You can do:

$func = "print";
&$func("hello");

sub print
{
 print @_[0];
}

But I want to call built in perl functions.

Thx,

- T

#Just Another Perl Hacker
open(_=>${$[|$|})||die;($_=<_>)=~s#^\### ; print



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

Date: Wed, 3 Sep 1997 12:50:25 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Jordyn A. Buchanan" <jordyn@bestweb.net>
Subject: Re: Q: assoc. arrays as subroutine argument
Message-Id: <Pine.GSO.3.96.970903124705.11990N-100000@julie.teleport.com>

On Tue, 2 Sep 1997, Jordyn A. Buchanan wrote:

> It's probably a lot more reliable that way, but this works pretty well
> in a practical sense: 
> 
>    sub ascii2html {
>    my %myhash = @_;
>    foreach $wert (keys %myhash) {
>    ...

Yes, that _works_, but don't try it on a very large hash - You're having
to turn the hash into one long list, and then build a whole new hash out
of the list! That might be unavoidable (or at least what you want to do)
at times, but it's generally better to pass a single scalar (a reference)
rather than the entire hash. 

Of course, using references is the only good method to pass around more
than one list or hash at a time. 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 3 Sep 1997 12:31:25 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "The Infamous BooBoo Q. Earp." <00mslantz@bsuvc.bsu.edu>
Subject: Re: Query Strings & CGI's
Message-Id: <Pine.GSO.3.96.970903121731.11990J-100000@julie.teleport.com>

On 1 Sep 1997, The Infamous BooBoo Q. Earp. wrote:

> How do I send a query string via a normal URL?

I use the GET method, as documented in the HTTP specification.

    http://www.ics.uci.edu/pub/ietf/http/rfc1945.html

The people in a web-related newsgroup probably have a better and more
complete answer to this, and they probably already put it into their FAQ. 

> And you get bonus points if you can tell me what I'm doing wrong.

You're asking a non-Perl question in a Perl newsgroup. (There's nothing
wrong with the fact that this is a web-related question. But there's
nothing Perl-specific about it: The answer to your question would be the
same if your script were a shell script or COBOL, Ada, or APL. So it's not
a Perl question; in this case it's a web question, and you'll likely get
better and more complete answers in a web-related newsgroup.) 

> Please mail me directly, I won't be checking this newsgroup.

On Usenet, everyone contributes in whatever way they can. What you're
doing here is like walking in on a potluck dinner and asking for a free
meal to go. I'm sure you didn't mean to do anything so rude as that. 
Please, stay around Usenet and help where you can. And when you have Perl
questions which aren't already answered in the docs and FAQs, feel free to
ask them here. Thanks! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 Sep 1997 14:45:46 -0400
From: jin yu <jinyu@cs.sunysb.edu>
Subject: question about perlembed
Message-Id: <340DB05A.A02@cs.sunysb.edu>


hi, I have problem about C call perl function.
I tried the example about pattern matching in the perlembed section.
when the pattern is exiting in the string, it works.
When the pattern is not exiting in the string, it creats the core dump.
I'm glad if somebody can help me.
Jin
email jenny@sun2.bnl.gov


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

Date: Wed, 3 Sep 1997 12:12:40 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tracy Bednar <spectran@netcom.com>
Subject: Should you close files (was: Re: Pattern Matching with Arrays)
Message-Id: <Pine.GSO.3.96.970903120015.11990H-100000@julie.teleport.com>

On Wed, 3 Sep 1997, Tracy Bednar wrote:

> I read that you shouldn't close files, Perl will do this for you??? 

You don't usually _need_ to close a filehandle, since it'll be
automatically closed when your process exits or when you re-open the
filehandle. But if you have written a file from a long-running process,
it's often good to close a file when you're done with it, to be sure that
the buffers are all flushed and to release any locks you have on the file.
(If you're worried about running out of file descriptors, that's another
reason to use close.) I like to be tidy in my code, though, and so I
normally use one close for every open. It's your choice.

As they say at the nudist colony, you don't have to use close.

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 Sep 1997 20:42:42 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Re: Simple Perl for  Win 32 Question (not in FAQ)
Message-Id: <340da794.5490678@news.supernews.com>

On 2 Sep 1997 15:23:01 -0700, klander@primenet (Kevin) wrote:

>On Tue, 02 Sep 1997 21:52:21 GMT, twheeler@m-net.arbornet.org (T.
>Wheeler) wrote:
>
>$filename =~ /^(.+\\)(.*)$/;  # <-- extracts path and filename into $1
>                              #     and $2
>
>$fpath = $1;
>$fname = $2;

Doesn't work for $filename eq '\\autoexec.bat'

It also assumes (IMHO mistakenly) that it was given a filename
separated by backslashes, while Perl itself is content with slashes
(which I prefer to type when I can, since they're in the same place on
all keyboards.)

--
Ron Parker
Software Engineer
Farm Works Software       Come see us at http://www.farmworks.com
For PGP public key see http://www.farmworks.com/Ron_Parker_PGP_key.txt


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

Date: 3 Sep 1997 20:25:09 GMT
From: Lou Poppler <lwp@flenser.att.net>
Subject: Re: Telnet Parameters?  Please Help!
Message-Id: <5ukh35$jlc@bgtnsc02.worldnet.att.net>


In comp.lang.perl.modules Marc Philips <Marc.Philips@tvd.be> wrote:
: Monachus Silentium wrote:

: > I've got a telnet client which is terribly simple (slightly modified
: > version of the one in the O'Reilly book or the perlipc manpage), but it has
: > a huge flaw.
: >
: > It connects to a server on a specific port (not port 23).  The server
: > outputs a screen of information before asking for a login.  My client
: > receives all of this information
: > except for the login.  It isn't until after the connection times out that
: > the login request is displayed.

: My guess is that your client reads lines of text with the <filehandle>
: operator. The "information" lines that the server sends to your client are all
: terminated with a CRLF but the line containing the login prompt isn't so your
: <> never returns until the server closes the connection.

: Try using sysread to get bytes (not lines) from your socket and select to find
: out if there is anything to read (see the perlfunc man page).

[snip of STUPID html copy of Marc.Philips@tvd.be's followup, and of 
 HUGE "signature" of his message]

Marc is correct.  Another solution is to do this:
$/ = "\:";     # change the input record separator to colon (before you read)
(depending on exactly what you are doing, you might also want to:)
$* = 1;        # consider match string to be multi-line



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

Date: Wed, 03 Sep 1997 15:27:13 -0500
From: Kermit Tensmeyer <kermit@ticnet.com>
Subject: Re: Who is still interested in SOCKS?
Message-Id: <340DC821.92F1BF46@ticnet.com>

Mark A. Lehmann wrote:
> 
> Post here if you want perl to support SOCKS (socks4) in the IO::Socket::Inet
> module.

  but of course, i'm interested.  But why stop at socks4, why not do
 something really usefull like socks5?


>  I would like to see this socks support written in a
> perl module (either in XS, SWIG, or in perl source code) instead of having it
> be compiled in place of the regular modules.  I would like
> IO::Socket::Inet->new() to have an option to use a socks proxy for the TCP
> connection.

 I'm just a little curious.. how would this be implemented? Would it be
necessary
 to explictly option the new to be a socks enabled structure or
 would it be easier to set it up so that 
   If the socks flag is turned on, then all connections on the network
 would obey the socks configuration rules. ( all connections to this
subnet,
 or using this protocol bypass the socks server.)

 In the new version of Emacs (sub-directory W3) there is a lisp module
 for socks5 written by William Perry (who is now involved in socks
development
 at Aventail.)  It may be useful in determining methods in solving the 
 problem.

 Hey, if it can be done in lisp without requiring XS, or SWIG type
processing
 it can be done better (much, much better) in Perl.



> I'm willing to write the code, but if no one here wants it, I'm not going to
> package it up for CPAN.
> 
> I would also like some pointers from the IO::Socket developers.
> 
> --
> Mark Lehmann.

-- 
-------
  Kermit Tensmeyer
  Kermit@ticnet.com


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

Date: Wed, 3 Sep 1997 12:39:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: COWBYS <cowbys@aol.com>
Subject: Re: WHY doesnt this work ??
Message-Id: <Pine.GSO.3.96.970903123453.11990K-100000@julie.teleport.com>

On 3 Sep 1997, COWBYS wrote:

> open ( DELFTP, ">>$delftp") || die "Cant find $delftp !!, $! \n";
> opendir( WEBAPPS, "$webappdir") || die "Cant open $webappdir !!, $!" ;

Those quote marks around the directory name are merely misleading.

> @APPS = readdir(WEBAPPS);
>   foreach $file (@APPS) {

If you don't need to have the list of files in @APPS for later, you could
make this simpler and less of a potential memory hog by replacing those
two lines with this one.

    while (defined($file=readdir WEBAPPS)) {

Well, it seems simpler to me... :-)

>     if (-f $file) {

When you're doing this test, Perl has no way of knowing that you mean
"$file in the directory used in that readdir". You're asking it whether
that file name exists in the current directory. You probably meant to use
something like this.

    if (-f "$webappdir/$file") {

>       print DELFTP "del $file \n"; }  
>   }

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 03 Sep 1997 16:23:46 -0400
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: WHY doesnt this work ??
Message-Id: <fl_aggie-ya02408000R0309971623460001@news.fsu.edu>


In article <19970903175101.NAA22485@ladder01.news.aol.com>, cowbys@aol.com
(COWBYS) wrote:

+ I am trying to test the file first, before copying it to be sure it is not
+ empty, i dont want to copy empty files or dirs.. but why doesnt this code
+ work.?

Because the code does not do what you think it does?

+ NOTE: if I take out the if,  (if -f $file), it works fine, but it wont write
+            any output if I include the "if" test... any help appreciated

I see...more support for my first remark...

[this is the if test in question...]

+     if (-f $file) {

-f $file   file is a plain file
(pg 85, the 2nd edition of the camel book, or under the unary operators
 in the on-line help, perlop section, I think)

If this was a directory full of binary executables (apps, yes?), they
shouldn't be considered "plain" files. But perl scripts would (should?)
be considered plain files (I tested this on our unix box and perl 5.003,
and they are plain files).

Now, if you want to check on the size and not copy zero-length files, you
want a different test:

if (-z $file) { file has zero size, yadda yadda yadda ;}

James

-- 
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: 03 Sep 1997 16:42:53 -0400
From: Douglas McNaught <doug@ono.tc.net>
Subject: Re: WHY doesnt this work ??
Message-Id: <m2afhu6sdu.fsf@ono.tc.net>

fl_aggie@hotmail.com (I R A Aggie) writes:

> -f $file   file is a plain file
> (pg 85, the 2nd edition of the camel book, or under the unary operators
>  in the on-line help, perlop section, I think)
> 
> If this was a directory full of binary executables (apps, yes?), they
> shouldn't be considered "plain" files. But perl scripts would (should?)
> be considered plain files (I tested this on our unix box and perl 5.003,
> and they are plain files).

Binaries are plain files.  Things that are not plain files:

* Directories
* Sockets
* Device entries
* Symlinks
* Named pipes (FIFOs)

-Doug
-- 
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";


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

Date: Wed, 03 Sep 1997 12:57:28 -0700
From: Axel Schweiger <axel@apl.washington.edu>
Subject: Win32/ Perl -S (pl2bat)
Message-Id: <340DC128.5709@apl.washington.edu>

I am having problems getting the pl2bat or its derivatives to work on 
my Windows 95 machine. I am using the latest built from Activeware:

Win32 Build 307 (5.0003_07)

The problem seems to be that pl2bat (or equivalents) insert the 
-S command. On my machine perl -S test.pl yields:
  can't execute test.pl. When I edit out -S things actually do work.

I have followed the instructions for installation in the Win95.txt
file but can't seem to make things work.

Thanks
Axel


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

Date: 03 Sep 1997 14:30:02 -0600
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
To: Todd Beverly <beverly@kodak.com>
Subject: Re: Wrote new module, need help with system dependencies.
Message-Id: <omwwkyjg3a.fsf@tees.cs.ualberta.ca>

In article <340D716A.1AC05DA5@kodak.com> Todd Beverly <beverly@kodak.com> writes:

> I need to differentiate operating systems in order to
> properly determine floats.
No, you need to differentiate CPU types, more specifically endianness.
What if your script is run on Linux (ie a PC)?

> My first thought was to add an entry to Makefile.PL to determine the OS type
> during the make
It's better to do your test at run-time (it's not expensive). You can
determine endianness using pack. From perlfunc:
          $foo = pack("s2",1,2);
          # "\1\0\2\0" on little-endian
          # "\0\1\0\2" on big-endian
Or try these examples:                               (on sun4m sparc)
        print unpack("h8",pack("L",0x12345678))      21436587
        print unpack("h8",pack("N",0x12345678))      21436587
        print unpack("h8",pack("V",0x12345678))      87654321
L is the native long (32-bit), N is big-endian (network order), "V" is
little-endian (VAX). Therefore, sparc is a big-endian machine.



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

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

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