[11154] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4754 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 26 18:07:12 1999

Date: Tue, 26 Jan 99 15:00:20 -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           Tue, 26 Jan 1999     Volume: 8 Number: 4754

Today's topics:
        anonymous blocks of code? cshupp@my-dejanews.com
    Re: anonymous blocks of code? <tchrist@mox.perl.com>
    Re: anonymous blocks of code? (Sean McAfee)
    Re: Can perl make popup window like Javascript scraig@my-dejanews.com
    Re: CGI, Xitami and other modules <Savage.Ron.RS@bhp.com.au>
    Re: database in perl (Abigail)
    Re: Deleting dupes with Perl (Larry Rosler)
    Re: Deleting dupes with Perl droby@copyright.com
    Re: Deleting dupes with Perl (Abigail)
    Re: edit @INC?/DBI install--Can't locale Config.pm <Savage.Ron.RS@bhp.com.au>
    Re: Getting UNIX Filesystems list? <gellyfish@btinternet.com>
    Re: Help on Change Case Susbtitution (Larry Rosler)
    Re: How to change @INC path permenantly? <Savage.Ron.RS@bhp.com.au>
    Re: impossible configure perl CGI on IIS4? <joe@iss-corp.com>
    Re: libwww and broken pipe? (I R A Aggie)
        Linux device programming - Yeasu RT-50 <xmiles@earthlink.net>
        Looking for SNMP Poller <grossi@fas.harvard.edu>
        loops <yhu@mail.nih.gov>
    Re: loops (Alastair)
    Re: loops <yhu@mail.nih.gov>
    Re: loops <dgris@moiraine.dimensional.com>
    Re: Number manipulation and time formats (Larry Rosler)
    Re: Number manipulation and time formats <kimntodd@dontspamus.execpc.com>
    Re: Number manipulation and time formats <kimntodd@dontspamus.execpc.com>
    Re: Number manipulation and time formats (I R A Aggie)
    Re: Perl - Novell - Upload problem with cgi-lib : File  <gellyfish@btinternet.com>
    Re: Perl Criticism [summary] (I R A Aggie)
        perlcc problem (some compilled programs doesn't running <fooly@sztaki.hu>
    Re: Problems using Perl and Cygnus Bash <gellyfish@btinternet.com>
        Semantics of File::Copy::copy(,) chess@watson.ibm.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Tue, 26 Jan 1999 21:57:02 GMT
From: cshupp@my-dejanews.com
Subject: anonymous blocks of code?
Message-Id: <78ldna$h8n$1@nnrp1.dejanews.com>

Fellow JAPH's,

I really, really want to do this:

my $node_list={ open(DATA,"Unix_boxes.txt") || die "Couln't open
Unix_boxe.txt : $!\n";					 my @array=<DATA>;   
			   chomp @array;				  
return \@array};

instead of this:

my $node_list = sub { open(DATA,"Unix_boxes.txt") || die "Couln't open
Unix_boxe.txt : $!\n";
				  my @array=<DATA>;
				  chomp @array;
				  return \@array;};
$node_list=&$node_list;

If I am inadvertently opening up an old can of worms I apolagize.
PLEASE e-mail responses to me at cshupp@entergy.com

<A HREF="mailto:cshuppt@entergy.com">Cris Shupp</A>

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


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

Date: 26 Jan 1999 15:21:15 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: anonymous blocks of code?
Message-Id: <36ae3fdb@csnews>

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

In comp.lang.perl.misc, 
    cshupp@my-dejanews.com writes:
:Fellow JAPH's,
:
:I really, really want to do this:
:
:my $node_list={ open(DATA,"Unix_boxes.txt") || die "Couln't open
:Unix_boxe.txt : $!\n";					 my @array=<DATA>;   
:			   chomp @array;				  
:return \@array};
:
:instead of this:
:
:my $node_list = sub { open(DATA,"Unix_boxes.txt") || die "Couln't open
:Unix_boxe.txt : $!\n";
:				  my @array=<DATA>;
:				  chomp @array;
:				  return \@array;};
:$node_list=&$node_list;

Well, you can do all those, although I don't know why
you did the last one that way.  The second could have
been written this way:

my $node_list = sub { 
    open(DATA,"Unix_boxes.txt") || die "Couln't open Unix_boxe.txt : $!\n";
    my @array=<DATA>;
    chomp @array;
    return \@array;
}->();

But that's overkill.  Just use do{}.  Why do people
forget this?  They forget do $file, too.

my $node_list = do { 
    open(DATA,"Unix_boxes.txt") || die "Couln't open Unix_boxe.txt : $!\n";
    my @array=<DATA>;
    chomp @array;
    \@array;
};

Once you see the similarities (and differences) between sub{}, do{},
and eval{}, many possibilities should occur to you.

--tom
-- 
MSDOS was created to keep idiots away from Unix


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

Date: Tue, 26 Jan 1999 22:41:02 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: anonymous blocks of code?
Message-Id: <2wrr2.4133$Ge3.17561713@news.itd.umich.edu>

In article <36ae3fdb@csnews>, Tom Christiansen  <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
>In comp.lang.perl.misc, 
>    cshupp@my-dejanews.com writes:
>:I really, really want to do this:
>:my $node_list={ open(DATA,"Unix_boxes.txt") || die "Couln't open
>:Unix_boxe.txt : $!\n";					 my @array=<DATA>;   
>:			   chomp @array;				  
>:return \@array};

>:instead of this:
>:my $node_list = sub { open(DATA,"Unix_boxes.txt") || die "Couln't open
>:Unix_boxe.txt : $!\n";
>:				  my @array=<DATA>;
>:				  chomp @array;
>:				  return \@array;};
>:$node_list=&$node_list;

>Just use do{}.  Why do people
>forget this?  They forget do $file, too.

My current favorite Perl idiom, as posted by Abigail in
alt.sysadmin.recovery not long ago:

my @lines_in_file = do { local @ARGV = qw{filename}; <> };

My own variation:

my $file_contents = do { local (@ARGV, $/) = 'filename', <> };

>my $node_list = do { 
>    open(DATA,"Unix_boxes.txt") || die "Couln't open Unix_boxe.txt : $!\n";
>    my @array=<DATA>;
>    chomp @array;
>    \@array;
>};

Or, if you don't mind a bit of obfuscation:

my $node_list;
chomp(@{ $node_list = [ do { local @ARGV = 'Unix_boxes.txt'; <> } ] });

>Once you see the similarities (and differences) between sub{}, do{},
>and eval{}, many possibilities should occur to you.

Oh, they do, they do!

-- 
Sean McAfee -- mcafee@umich.edu
sub AUTOLOAD { $AUTOLOAD=~m((([A-Z])|.)$); sub r; print $2&&" ",$1 }&
J&&&u&&&s&&&t&&&A&&&n&&&o&&&t&&&h&&&e&&&r&&&P&&&e&&&r&&&l&&&H&&&a&&&c&&&k&&&e&&r


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

Date: Tue, 26 Jan 1999 21:31:00 GMT
From: scraig@my-dejanews.com
Subject: Re: Can perl make popup window like Javascript
Message-Id: <78lc6k$fro$1@nnrp1.dejanews.com>

In article <78hgg8$aep$1@nnrp1.dejanews.com>,
  leostar@mailcity.com wrote:
> Hi
>       I just want to know that can perl/CGI make a Popup Window like
> Jacascript. Because I see some page in Fortune city homepage when I click at
> edit page, it will popup a new window. But when I look at the page source. I
> can't see any code in Javascript Language.
>       Would anyone tell me how they do that? I would use it in my project.
>       Thanks for your help.
>                                        Red Wine

 This is really a HTML question. In the anchor tag for the link place a target
attribute with the name that doesn't match a frame or window already.  Then a
new window of that name will be created.

eg.  <a href="../edit.html" target="edit_window">edit page</a>

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


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

Date: Wed, 27 Jan 1999 09:24:17 +1100
From: "Ron Savage" <Savage.Ron.RS@bhp.com.au>
Subject: Re: CGI, Xitami and other modules
Message-Id: <78lf6c$k917@atbhp.corpmel.bhp.com.au>

A guess:
1. You put your modules in a non-standard place
2. From the command line they are found via PERL5LIB
3. Xitami does not honour PERL5LIB

--
Ron Savage
Office (preferred): Savage.Ron.RS@bhp.com.au
Home: rpsavage@ozemail.com.au
http://www.ozemail.com.au/~rpsavage
A.J. Norman wrote in message <78kcej$8fb@harrier.le.ac.uk>...
> I'm writing CGI scripts for the Xitami webserver on an NT machine,
> with Perl 5.005_02 (ActiveState build 509).
>
> I want to be able to use my own module within the CGI script - at the
> moment I'm having to put mylib.pm into the standard Perl library
> directory, C:\perl\lib.  Srinivasan's "Advanced Perl Programming"
> lists three ways of putting another directory into Perl's load path,
> and I have tried a couple of them - they work when I run the CGI
> script from the command line, but when it's running via the server
> nothing happens (which I assume means the module isn't being found,
> hence @INC isn't being altered).  It's a minor problem, but I'd
> really prefer not to have to put my own modules in with the main Perl
> distribution if there's another way of doing it.
>
>--
>Andrew Norman, Leicester, England
>nja@le.ac.uk || andrew.norman@le.ac.uk
>http://www.le.ac.uk/engineering/nja/




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

Date: 26 Jan 1999 21:49:17 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: database in perl
Message-Id: <78ld8t$b2m$1@client2.news.psi.net>

Karen Soudry (karenl@security7.com) wrote on MCMLXXIV September MCMXCIII
in <URL:news:78k094$dok$1@news.netvision.net.il>:
== 
== I need codes and examples on how to write a database in perl and the method
== "search" in perl!!!


If you're not more specific than "write a database", I would suggest
using a hash.

Of course, if you have more requirement, you quickly come to the state
were you shouldn't do it in Perl anymore.



Abigail
-- 
perl -wle 'print "Prime" if (0 x shift) !~ m 0^\0?$|^(\0\0+?)\1+$0'


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

Date: Tue, 26 Jan 1999 13:34:31 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Deleting dupes with Perl
Message-Id: <MPG.1117d4c3c66bf94b9899cb@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <78l8t4$dbh$1@nnrp1.dejanews.com> on Tue, 26 Jan 1999 
20:34:45 GMT, dturley@pobox.com <dturley@pobox.com> says...
> In article <78km8q$ss6$1@nnrp1.dejanews.com>,
>   jxdub@my-dejanews.com wrote:
> > but now I need to delete the
> > duplicates...  Could anyone tell me a good way to do this? The file would
> 
> here's one way. put the file into @out, sort it, then print it.
> 
> @sorted = sort @out;
> $prev = 'nonesuch';
> @n_out = grep($_ ne $prev && ($prev = $_), @sorted); #remove duplicates

This also deletes entries whose value is false, such as '0', as is 
mentioned in the FAQ you copied this from.  Why not simply aim the 
questioner to the FAQ (as two of us have already), so he can get the 
whole story?

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


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

Date: Tue, 26 Jan 1999 21:33:00 GMT
From: droby@copyright.com
Subject: Re: Deleting dupes with Perl
Message-Id: <78lcac$g3n$1@nnrp1.dejanews.com>

In article <78l8t4$dbh$1@nnrp1.dejanews.com>,
  dturley@pobox.com wrote:
> In article <78km8q$ss6$1@nnrp1.dejanews.com>,
>   jxdub@my-dejanews.com wrote:
> > but now I need to delete the
> > duplicates...  Could anyone tell me a good way to do this? The file would
>
> here's one way. put the file into @out, sort it, then print it.
>
> @sorted = sort @out;
> $prev = 'nonesuch';
> @n_out = grep($_ ne $prev && ($prev = $_), @sorted); #remove duplicates
>
>         foreach $address (@n_out) {
>                 print "$address\n";
>         }
>

Or there are several other ways to do it in perlfaq4 under the heading

	"How can I extract just the unique elements of an array?".

--
Don Roby

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


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

Date: 26 Jan 1999 21:50:26 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Deleting dupes with Perl
Message-Id: <78ldb2$b2m$2@client2.news.psi.net>

jxdub@my-dejanews.com (jxdub@my-dejanews.com) wrote on MCMLXXIV September
MCMXCIII in <URL:news:78km8q$ss6$1@nnrp1.dejanews.com>:
::                                                        I need to delete the
:: duplicates...

FAQ



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Wed, 27 Jan 1999 09:19:19 +1100
From: "Ron Savage" <Savage.Ron.RS@bhp.com.au>
Subject: Re: edit @INC?/DBI install--Can't locale Config.pm
Message-Id: <78let2$k916@atbhp.corpmel.bhp.com.au>

Also consider the env var PERL5LIB.

--
Ron Savage
Office (preferred): Savage.Ron.RS@bhp.com.au
Home: rpsavage@ozemail.com.au
http://www.ozemail.com.au/~rpsavage
Mark Hamlin wrote in message <36ADF649.1EC2122D@bt.com>...
>I think I've figured it, I'm now trying to confirm that I use the: use lib
>(LIST);
>method.
>
>Does this sound right, to permenantly change the path contained in @INC?
>
>Mark Hamlin




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

Date: 26 Jan 1999 22:18:58 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Getting UNIX Filesystems list?
Message-Id: <78lf0i$1rn$1@gellyfish.btinternet.com>

On Mon, 25 Jan 1999 11:26:27 +0000 iqbal wrote:
> Hi
> 
> Jonathan Stowe wrote:
>> 
>> On Thu, 07 Jan 1999 16:20:56 GMT lethr@my-dejanews.com wrote:
>> > Is there a good way to get a list of mounted filesystems within perl?  (other
>> > than using a system call or reading fstab).  Ideally, I'd like to get results
>> 
>> I would do *that* like:
>> 
<snip>
>> 
>> 
> Cant you just read the fstab file, or have I missed something
> 

Er yes he said he didnt want to read fstab ;-}

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 26 Jan 1999 12:48:18 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help on Change Case Susbtitution
Message-Id: <MPG.1117c9e9b02d7489899c9@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36AE0FEE.B33B3BB1@email.sps.mot.com> on Tue, 26 Jan 1999 
11:56:54 -0700, Omar Soto <rp7667@email.sps.mot.com> says...
>     Need some help in making or using a currently available
> library function that will perform the following substitution:
> 
> $var =~ s/[A-Z]..[A-Z]/[a-z]..[a-z]/;   # i.e.  P76r  =>
> p76r       P76R => p76r    p76R => p76r

The function is 'lc', and you can use it in the substitution side of the 
expression:

  $var =~ s/([A-Za-z])(..)([A-Za-z])/lc($1) . $2 . lc($3)/e;

Of course, that would also change 'fooP76Rbar' to 'foop76rbar', which 
you can fix with suitable anchors, if you wish.

I fixed your pattern match regex to deal with 'P76r' and 'p76R', which 
yours woud not have.

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


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

Date: Wed, 27 Jan 1999 09:16:01 +1100
From: "Ron Savage" <Savage.Ron.RS@bhp.com.au>
Subject: Re: How to change @INC path permenantly?
Message-Id: <78lemv$k915@atbhp.corpmel.bhp.com.au>

Use the environment variable PERL5LIB to point to one or more dirs.

--
Ron Savage
Office (preferred): Savage.Ron.RS@bhp.com.au
Home: rpsavage@ozemail.com.au
http://www.ozemail.com.au/~rpsavage
Mark Hamlin wrote in message <36AD9DA6.E7009072@bt.com>...
>How do I change the @INC path permenantly?  Installing perl 5.005 using a
pkgadd
>Solaris build, it did not set the path correctly.
>
>Thanks, Mark.
>
>ps please send me a respose vua e-mail.
>--
>
>        ___....-----'---'-----....___
>  =========================================
>         ___'---..._______...---'___
>        (___)      _|_|_|_      (___)
>          \\____.-'_.---._'-.____//
>            ~~~~'.__'---'__.'~~~~
>                   ~~~~~~~
> 'More speed'
>   Sisco
>
>Work: mailto:mark.c.hamlin@bt.com
>Personal: mailto:mark@dimitrinet.demon.co.uk
>
>Please use you auto reply where possible to distribute to both mailboxes.




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

Date: Tue, 26 Jan 1999 16:01:01 -0500
From: "Joseph Pecora" <joe@iss-corp.com>
Subject: Re: impossible configure perl CGI on IIS4?
Message-Id: <Opu8d7WS#GA.230@uppssnewspub05.moswest.msn.net>

Try putting %s %s at the end of your mapping:
    perl\bin\perl.exe %s %s
Helped me.

foobar678@my-dejanews.com wrote in message
<78kv20$4rl$1@nnrp1.dejanews.com>...
>*The folder it's in is marked executable.
>*The "Application Settings"|Configuation contains the
> correct mappings for .pl files.
>*The script checkbox is checked
>*I ran the adsutil script and "adsutil set w3svc/CreateCGIWithNewConsole
TRUE"
> and it seemed to work.
>
>Nothing I do gets perl CGI to run. The perl script is
>very simple, it contains:
>  print "Content-Type: text/plain\n\n";
>  print "Hello, Perl world!\n";
>
>And ever time you click on the file, for a millisecond a console
>window flashes and the "you have chosen to download a file" box
>also flashes. Then Nothing.
>
>I am beginning to think IIS is a big piece of shit.
>Help is possible.
>
>
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own




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

Date: Tue, 26 Jan 1999 16:18:43 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: libwww and broken pipe?
Message-Id: <fl_aggie-2601991618430001@aggie.coaps.fsu.edu>

In article <78l6vb$bsj$1@nnrp1.dejanews.com>, ftn@yesbox.net wrote:

+ Greetings, thanks for your answer,

Sure.

+ > Could you show us a bit of code? just enough to allow someone to replicate
+ > your problem?
 
+ here it is (but read my comments below first):
 
+ sub myGet{
+     my($url) = @_;
+ 
+     my $ua = new LWP::UserAgent;

I dunno if you call this from elsewhere, but...when I tried this code
snippet, perl barked at me, and required me to add:

    require LWP::UserAgent;

as per the LWP::UserAgent document, so you must have this somewhere, or
you wouldn't even get a broken pipe. I fixed this, and got it to work
for me.

+ Seems like lynx and lwp-download dies of Broken pipe as well,

That's not a good sign. That's a real bad sign. I'd say that something
is foobar on your system, and it needs fixing. And it doesn't seem to
be in your perl setup, since lynx isn't working quite right, either.

+ tried fetching the documents by doing a slogin to another server and fetch
+ them from there and that worked,

Have you tried your program on that machine?

+ Can i trap this signal in some easy way in perl, so it just will go on?

Yes. See 'perldoc perlipc', as referenced by the FAQ (#8, 'How do I trap 
control characters/signals?'). I haven't ever needed to do this, I just
know you can.

James


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

Date: Tue, 26 Jan 1999 14:38:59 -0800
From: "Miles M." <xmiles@earthlink.net>
Subject: Linux device programming - Yeasu RT-50
Message-Id: <36AE4403.6EFEA51D@earthlink.net>

I am new to Linux and programming. I  picked up the Camel book and am
about half way through. My question is that I am now getting into ham
radio and would like to write a program that would program the RT-50
radio I use. Should I continue with perl or is there  another
programming language that would be more appropriate for this task.  I
see my self continuing in the device programming branch. Any one out
there that programs devices and experience with perl?

-Miles




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

Date: Tue, 26 Jan 1999 15:47:13 -0500
From: Tom Grossi <grossi@fas.harvard.edu>
Subject: Looking for SNMP Poller
Message-Id: <36AE29D1.78D7AA47@fas.harvard.edu>


I am looking for an SNMP poller written in Perl which does not block
when
devices are not responding (e.g. one which receives and sendslls with
separate processes
or threads.)  Any help on where I could find such a module or how to
modify an existing
module to do this would be greatly appreciated.  Thanks. -Tom



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

Date: Tue, 26 Jan 1999 16:17:14 -0500
From: Ying Hu <yhu@mail.nih.gov>
Subject: loops
Message-Id: <36AE30D9.77C37E99@mail.nih.gov>

Hi:
How to use loops to print an array (@stuff) as the following:
$stuff[0]
$stuff[1]
$stuff[2]
 ...
$stuff[n]
$stuff[0] $stuff[1]
$stuff[0] $stuff[2]
$stuff[0] $stuff[3]
 ...
$stuff[0] $stuff[1]...$stuff[n]

thanks

Ying Hu




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

Date: Tue, 26 Jan 1999 21:40:05 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: loops
Message-Id: <slrn7asdja.6d.alastair@calliope.demon.co.uk>

Ying Hu <yhu@mail.nih.gov> wrote:
>Hi:
>How to use loops to print an array (@stuff) as the following:
>$stuff[0]
>$stuff[1]
>$stuff[2]

Almost too basic to answer. You should try and learn a little more. Look for
'foreach'.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Tue, 26 Jan 1999 17:36:32 -0500
From: Ying Hu <yhu@mail.nih.gov>
Subject: Re: loops
Message-Id: <36AE4370.84F3145@mail.nih.gov>

Do you know the answer? I did not think so!

Alastair wrote:

> Ying Hu <yhu@mail.nih.gov> wrote:
> >Hi:
> >How to use loops to print an array (@stuff) as the following:
> >$stuff[0]
> >$stuff[1]
> >$stuff[2]
>
> Almost too basic to answer. You should try and learn a little more. Look for
> 'foreach'.
>
> --
>
> Alastair
> work  : alastair@psoft.co.uk
> home  : alastair@calliope.demon.co.uk





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

Date: 26 Jan 1999 15:59:10 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: loops
Message-Id: <m3pv81abep.fsf@moiraine.dimensional.com>

Ying Hu <yhu@mail.nih.gov> writes:

> Alastair wrote:
> 
> > Ying Hu <yhu@mail.nih.gov> wrote:

> > >How to use loops to print an array (@stuff) as the following:
> > >$stuff[0]
> > >$stuff[1]
> > >$stuff[2]

>> Almost too basic to answer. You should try and learn a little
>> more. Look for 'foreach'.

> Do you know the answer? I did not think so!

Just like he said, use for (or foreach, they're synonymous).

$ perl -le '@a=(1..2);print for @a'
1
2
$

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
Perl/C/Unix/Java hacker looking for a position.


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

Date: Tue, 26 Jan 1999 12:57:10 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Number manipulation and time formats
Message-Id: <MPG.1117cc058c6806d69899ca@nntp.hpl.hp.com>

In article <78l6ve$jg2$1@news1-alterdial.uu.net> on Tue, 26 Jan 1999 
14:03:05 -0600, End User <kimntodd@dontspamus.execpc.com> says...
> Oops, I forget an element:
> 
> $a =243;
> $b = 54;
> if ($a >= 60){
>     $d = $a % 60;
>     $e = $a / 60;
>     @q = split(/\./,$e);
>     $h = @q[0];}
> print "$h:$d:$b\n";
> 
> Sorry for the oversight.

      $e = $a / 60;
      @q = split(/\./,$e);
      $h = @q[0];}

These three lines are remarkably costly, and the last line is wrong as 
well (as the '-w' flag would have told you -- use it ALWAYS).  What you 
want there is simply

      $h = int($a / 60);

perldoc -f int

As for your question about zero-padding, TIMTOWTDI, but my choice would 
be to use [s]printf, with the format specifier '%.2d' for each variable 
that you want to pad ($d and $b):

      printf "%d:%.2d:%.2d\n", $h, $d, $b;

perldoc -f sprintf

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


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

Date: Tue, 26 Jan 1999 15:29:01 -0600
From: "End User" <kimntodd@dontspamus.execpc.com>
Subject: Re: Number manipulation and time formats
Message-Id: <78lc0k$n24$1@news1-alterdial.uu.net>

This did the job:
if ($d < 10){
    $d = "0$d";}

End User wrote in message <78l6na$j98$1@news1-alterdial.uu.net>...
>I have a simple little snip of code that i am sure can be optimised, but
>here it is:
>
>$a =243;
>$b = 54;
>if ($a >= 60){
>    $d = $a % 60;
>    $e = $a / 60;
>    @q = split(/\./,$e);}
>print "$h:$d:$b\n";
>
>as you can see, it takes the number of minutes and converts it to hours and
>minutes. This is the output of the code:
>
>4:3:54
>
>it should be 4:03:54
>
>My question is how to easily convert the 3 into 03. Is there something that
>I can perform on the $d to determine if it is <10, change the format?
>
>I am fairly novice with PERL, although I have done some pretty fun stuff.
>Can someone help me out here?
>
>Thanks in advance.
>
>--
>Todd Hayward
>Global Analyst, Systems Engineer
>MCSE, Compaq ACT
>noc at bakernet dot com
>
>




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

Date: Tue, 26 Jan 1999 15:39:40 -0600
From: "End User" <kimntodd@dontspamus.execpc.com>
Subject: Re: Number manipulation and time formats
Message-Id: <78lckh$ndm$1@news1-alterdial.uu.net>

Thanks for the tips.







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

Date: Tue, 26 Jan 1999 16:35:28 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Number manipulation and time formats
Message-Id: <fl_aggie-2601991635280001@aggie.coaps.fsu.edu>

In article <78l6na$j98$1@news1-alterdial.uu.net>, "End User"
<kimntodd@dontspamus.execpc.com> wrote:

+ 4:3:54
+ 
+ it should be 4:03:54
+ 
+ My question is how to easily convert the 3 into 03. Is there something that
+ I can perform on the $d to determine if it is <10, change the format?

You mean like sprintf/printf?

+ I am fairly novice with PERL, although I have done some pretty fun stuff.
+ Can someone help me out here?

Sure! Here's a good tip: become acquainted with the FAQ and the documentation,
both should be in your distribtution of perl. They have the advantage of
being on your machine, of being searchable, and you don't have to wait till
someone on Usenet gets around to writing something...

+ MCSE, Compaq ACT

I know what the first one is, but the second? what the hey is an ACT?

James


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

Date: 26 Jan 1999 21:10:33 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Perl - Novell - Upload problem with cgi-lib : File bigger!
Message-Id: <78lb09$1rd$1@gellyfish.btinternet.com>

On Mon, 25 Jan 1999 09:40:52 -0500 Pierre Ouimet wrote:
> Hi !
> 
> I used cgi-lib.pl to upload with fup.cgi  (That a demo a found).
> I'm on Novell, but seem to do the same thing on NT too.
> with the text file I don't have problem but with binary file.
> The file after uploaded was bigger ! 

binmode() see the perlfunc manpage.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 26 Jan 1999 16:40:22 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Perl Criticism [summary]
Message-Id: <fl_aggie-2601991640220001@aggie.coaps.fsu.edu>

In article <78kt31$33f$1@nnrp1.dejanews.com>, droby@copyright.com wrote:

+ It's definitely time to stop feeding the troll.

Oh, but he's such a cute little troll. I wonder which accounting department
lost him?

James - apologies, again, to Scott Adams...


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

Date: Tue, 26 Jan 1999 20:04:44 -0100
From: Fulajtar Pal <fooly@sztaki.hu>
Subject: perlcc problem (some compilled programs doesn't running)
Message-Id: <36AE4A0C.F6E9D0E1@sztaki.hu>

Hi,

  I tried perlcc with a very simple script:
----------------------------
#!/usr/bin/perl
while(<>)
  {
    print $_;
  }
----------------------------
The compillation (perlcc test.pl) was succesfull (without any warning or
erorr), but when I started this compilled program with a parameter
(example: test /etc/sendmail.cf) the program give me the following
message:
"Modification of a read-only value attempted at test.pl line 2."
, but when I running the original perl script (without compilation) the
progam runs ok.

Does anybody knows this problem?

With the simplest script:

#!/usr/bin/perl
print "Hello World!\n";

I didn't detected any problem.

Additional information:
Machine: HP vectra  iP166MMX/64MB main memory
OS version: RedHat linux 5.1
perl version: perl-5.005_02-2

Regards,

   Pal





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

Date: 26 Jan 1999 21:22:58 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Problems using Perl and Cygnus Bash
Message-Id: <78lbni$1rg$1@gellyfish.btinternet.com>

On Fri, 22 Jan 1999 01:18:19 GMT randall_burns@hotmail.com wrote:
> I've just tried several variations on using
> build 509 from ActiveState with bash from Cygnus.

<snip>

I think that you will have difficulty with using Cygwin bash with any Perl
other than one compiled using Cygwin32 because of the funny way that it
emulates Unix paths and mount-points and the like - it likes to render a
path like:

C:\blah

as something like:

//C/blah

It certainly does something strange with network drives.

If you want to use a version of bash  with Activestate Perl then you might
try out the djgpp version available from:

<http://www.delorie.com/>

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 26 Jan 1999 21:17:25 GMT
From: chess@watson.ibm.com
Subject: Semantics of File::Copy::copy(,)
Message-Id: <78lbcs$f86$1@nnrp1.dejanews.com>

I have a question on just what File::Copy::copy does.  In
particular, on my Win95 machine here running 5.004_02, the line

  print File::Copy::copy("foo.bar","c:\\t");

works just fine if c:\t is a directory.  It copies "foo.bar"
from the current directory to c:\t\foo.bar.  But is that
portable (modulo slash-slant)?  The perldoc description of
File::Copy:copy() doesn't really say.  Will it work that way
under AIX and MVS and OS/2 and Linux and BeOS and...?  Or,
to be safe, do I need to construct a complete filename for
the second argument, as in

  print File::Copy::copy("foo.bar","c:\\t\\foo.bar");

?  Thanks for any advice!

DC

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


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

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

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