Re: Is there a better way to get current tty name

2008-10-27 Thread Yue Chen
Sorry, I've got the answer.

It should be

$mytty = POSIX::ttyname(1);

2008/10/28 Yue Chen <[EMAIL PROTECTED]>:
> Hi
>
> I am writing a perl script which need send current tty to another program.
>
> Now i am using external cmd 'tty' and redirect the result to my
> variable, such as:
>
> $mytty = `tty`;
>
>
> Since sometimes 'tty' is not in my PATH, my script is not always
> successful. So is there a better perl internal mechanism to get such
> variable?
>
> Thank you very much
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Is there a better way to get current tty name

2008-10-27 Thread Yue Chen
Hi

I am writing a perl script which need send current tty to another program.

Now i am using external cmd 'tty' and redirect the result to my
variable, such as:

$mytty = `tty`;


Since sometimes 'tty' is not in my PATH, my script is not always
successful. So is there a better perl internal mechanism to get such
variable?

Thank you very much

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: Can any one tell me a better way to upload a file from the HTML form to a location in my home directorrt.

2006-04-07 Thread Moon, John


John W Moon
Systems Project Analyst

Enterprise Information Technology Services (EITS)
Department of Management Services
4030 Esplanade Way, Suite 260G
Tallahassee, Fl 32399-0950
Office: (850)922-7511
Email: [EMAIL PROTECTED]
Please note: Florida has a very broad public records law. Most written
communications to or from state officials regarding state business are
public records available to the public and media upon request. Your
e-mail communications may therefore be subject to public disclosure.


-Original Message-
From: Anish Kumar K. [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 06, 2006 5:45 AM
To: beginners@perl.org
Subject: Can any one tell me a better way to upload a file from the HTML
form to a location in my home directorrt.

I tried many ways, Though I am seeing the file. the SIZE IS 0.

I tried out these ways

First One

=
my $upload_file= $q->param('upload_file'); # This is the description
file which is being uploaded
if ($upload_file)
{
my $outfile="/home/anish/testing.doc";
open(OUTFILE,">$outfile") or warn "can't write $outfile: $!";
print OUTFILE <$upload_file>;
close(OUTFILE); 
}


Second Method


my $upload_file= $q->param('upload_file'); # This is the description
file which is being uploaded
my $outfile="/home/anish/testing.doc";
my $bytes_read=0;
my $size='';
my $buff='';
my $start_time;
my $time_took;

 if (!open(WFD,">$outfile"))
{
  print " Cannot Write the file ";
  exit(-2);
 }
 $start_time=time();
while ($bytes_read=read($upload_file,$buff,2096))
{
$size += $bytes_read;
binmode WFD;
print WFD $buff;
}

close(WFD);

 if ((stat $outfile)[7] <= 0)
{
unlink($outfile);
print "Could not upload file: $upload_file";
return;
}
else
{
$time_took=time()-$start_time;
  print "The Time Took  is $time_took and the size is $size";

 }




Here is part of what I do... This is pretty much from the docs... Hope
this helps get you started.. 
jwm

#-
sub ShowRequest {
unless ($dbh) {
$dbh=&MyConnect unless ($dbh);
}
$period = substr(&MyCurrent_Period($dbh),3); # format to "Mon-"
#
#   build list of files to upload
#
%files = ();
&GetFiles;
#
#   build "Put" select list
#
my (@put_list, %put_hash);
@put_list = ('None');
$put_hash{'None'} = '';
my $title;
foreach my $nm (keys %files) {
push @put_list, $nm; # key of r_import_files
$title = $files{$nm}{AKA};
$put_hash{$nm} = sprintf('%35s - %s', $title . '.' x (35 -
length($title)) , $files{$nm}{CREATED});
}
my $MyVerify = &IncludeScript('upload.js');
&MyStd_Caption($q,'TechDirect UpLoad
Services',$MyVerify,$q->br('Data UpLoads'),
'Browse for file to ' . $q->i('Get') . $q->br('and label with
required '. $q->i('Put') .  ' name.'),
$period);
print $q->start_multipart_form(-name=>'upload',
-onSubmit=>'return MyVerify(this);'),
$q->p({-align=>'CENTER'},
$q->checkbox(-name=>'REMOVE',
-label=>'Remove all existing files before Upload ?')),
$q->p(
$q->b('Get: '),
$q->filefield({-name=>'FILE',-size=>50})),
$q->p(
$q->table(
$q->Tr(
$q->td({-class=>'fix_xsmall'},[' ', 'Service
Items.. - Last Upload'])),
$q->Tr(
$q->td($q->b('Put: ')),
$q->td(
$q->popup_menu(-name=>'FILE_KNOWN_AS',
-values=>[EMAIL PROTECTED],
-default=>'None',
-labels=>\%put_hash,
-class=>'fix_xsmall'),
$q->p({-align=>'CENTER'},
$q->submit({-label=>'Send'})),
#   $q->submit({-label=>'Send', -onSubmit=>'return
MyVerify(this);'})),
$q->p(
$q->font({-color=>'RED'},
'Status :'),
$q->u($q->font({-color=>'BLUE'}, $status))),
$q->hidden(-name=>'UPLOAD',-value=>'YES'),
$q->end_form,
$q->end_html;
}
#---

Re: Can any one tell me a better way to upload a file from the HTML form to a location in my home directorrt.

2006-04-06 Thread JupiterHost.Net



Anish Kumar K. wrote:


I tried many ways, Though I am seeing the file. the SIZE IS 0.

I tried out these ways


use the upload() info in CGI.pm's POD, be sure to do it befpre any 
headers are output :)


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Can any one tell me a better way to upload a file from the HTML form to a location in my home directorrt.

2006-04-06 Thread Dr.Ruud
Anish Kumar K. schreef:

> I tried many ways, Though I am seeing the file. the SIZE IS 0.

Maybe this helps:
  http://perlmeme.org/tutorials/cgi_upload.html 

-- 
Affijn, Ruud

"Gewoon is een tijger."

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Can any one tell me a better way to upload a file from the HTML form to a location in my home directorrt.

2006-04-06 Thread Anish Kumar K.
I tried many ways, Though I am seeing the file. the SIZE IS 0.

I tried out these ways

First One

=
my $upload_file= $q->param('upload_file'); # This is the description file which 
is being uploaded
if ($upload_file)
{
my $outfile="/home/anish/testing.doc";
open(OUTFILE,">$outfile") or warn "can't write $outfile: $!";
print OUTFILE <$upload_file>;
close(OUTFILE); 
}


Second Method


my $upload_file= $q->param('upload_file'); # This is the description file which 
is being uploaded
my $outfile="/home/anish/testing.doc";
my $bytes_read=0;
my $size='';
my $buff='';
my $start_time;
my $time_took;

 if (!open(WFD,">$outfile"))
{
  print " Cannot Write the file ";
  exit(-2);
 }
 $start_time=time();
while ($bytes_read=read($upload_file,$buff,2096))
{
$size += $bytes_read;
binmode WFD;
print WFD $buff;
}

close(WFD);

 if ((stat $outfile)[7] <= 0)
{
unlink($outfile);
print "Could not upload file: $upload_file";
return;
}
else
{
$time_took=time()-$start_time;
  print "The Time Took  is $time_took and the size is $size";

 }




Re: A better way.

2005-08-02 Thread Dan Klose
Hi,

I have gone for the following code:

my %avs_dev = map{
  $_ => [mean($hoa{$_}), dev($hoa{$_})]
} keys %hoa;

for (sort {$avs_dev{$a}[0] <=> $avs_dev{$b}[0]} keys %avs_dev) {
  print "$_, $avs_dev{$_}[0], $avs_dev{$_}[1]\n";
}

I have never used MAP before... it looks handy!
Works a treat.

Thanks to Jeff 'japhy' Pinyan & Wiggins d'Anconia


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A better way.

2005-08-02 Thread Jeff 'japhy' Pinyan

On Aug 2, Dan Klose said:


my %hash_of_arrays2;

for (keys %hash_of_arrays) {
 my @array_of_data = exists($hash_of_arrays{$_})
   [EMAIL PROTECTED]
 :();


Given that you're iterating over the list of keys in %hash_of_arrays, 
there's NO reason to be using exists() here.


  my @array_of_data = @{ $hash_of_arrays{$_} };


 my $mean = mean([EMAIL PROTECTED]); #GET MEAN
 my $std_dev = dev([EMAIL PROTECTED]); #GET STANDARD DEV


There's no reason to make a COPY of the array and then dereference.  I'd 
suggest doing:


  my $data = $hash_of_arrays{$_};
  my $mean = mean($data);
  my $std_dev = dev($data);


 push @{$hash_of_arrays2{$_}}, $mean;
 push @{$hash_of_arrays2{$_}}, $std_dev;


You can do both at once:

  $hash_of_arrays2{$_} = [ $mean, $std_dev ];


}


You can make that for loop into one statement:

  my %hash_of_arrays2 = map {
$_ => [ mean($hash_of_arrays{$_}), dev($hash_of_arrays{$_}) ]
  } keys %hash_of_arrays;


for (sort {$hash_of_arrays2{$a}[0] <=> $hash_of_arrays2{$b}[0]}
keys %hash_of_arrays2) {

 print "$_, $hash_of_arrays2{$_}[0], $hash_of_arrays2{$_}[1]\n";
}


There's no way to eliminate the second loop, because you need to have all 
the data calculated before you can sort them.


--
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A better way.

2005-08-02 Thread Wiggins d'Anconia
Dan Klose wrote:
> Hello Everyone.
> 
> I have the following code:
> 
> 
> ### CODE BLOCK ###
> 
> my %hash_of_arrays2;
>

Have you considered a hash of hashes? For me, given the sample below, I
would prefer it, but obviously I haven't seen your whole script.

> for (keys %hash_of_arrays) {
>   my @array_of_data = exists($hash_of_arrays{$_})
> [EMAIL PROTECTED]
>   :();

I don't think the above is doing what you anticipate. 'exists' just
tests whether there is a key/value pair given the key. But since you are
iterating over the keys of the hash the test must always be true. If
there is no value, then your initialization will be the same as ()
anyways. So basically you can drop the above completely, or a better
check would be to test the number of elements (make sure you have an
array ref first if you are worried about it).

perldoc -f exists

> 
>   my $mean = mean([EMAIL PROTECTED]); #GET MEAN
>   my $std_dev = dev([EMAIL PROTECTED]); #GET STANDARD DEV
> 

Given that the above two functions take an array reference there is no
reason to dereference the array reference first, just to pass a
reference. You are using twice the memory to do so when the references
should allow you to save on memory that Perl would automatically duplicate.

>   push @{$hash_of_arrays2{$_}}, $mean;
>   push @{$hash_of_arrays2{$_}}, $std_dev;

This gets back to my question of the hash of hashes. Rather than
stuffing the mean and std_dev into indexes 0 and 1, why not just put
them in named indexes.

$hash_of_hashes->{$_}->{'mean'} = $mean;
$hash_of_hashes->{$_}->{'std_dev'} = $std_dev;

> }
> 
> for (sort {$hash_of_arrays2{$a}[0] <=> $hash_of_arrays2{$b}[0]} 
>  keys %hash_of_arrays2) {
> 
>   print "$_, $hash_of_arrays2{$_}[0], $hash_of_arrays2{$_}[1]\n";
> }
> 
> ### END OF CODE ###
> 
> If anyone has the time could you please show me ways of shortening this
> code e.g. eliminating the second for block (integration into the
> previous block) and any other tips / tricks.
> 

The problem is that to do a sort you have to know all of the values that
you are sorting on before you can start, which means you can't print the
output in a sorted manner in the first loop, so there really is no way
to combine the two. The best you could hope for would be to populate an
array in sorted order in the first loop and then just print the result
in the second, but your sorting routine would very likely be less
efficient than Perl's built-in one.

> There are no other people here that code perl and so I get no
> advice/feedback on how to improve my scripts.
>

You have come to the right place then. I know that feeling, it stinks.

> Thanks in advance.
> 
> Dan.

http://danconia.org

-- UNTESTED --
my %hash_of_calculations;
for my $key (keys %hash_of_arrays) {
  if (ref $hash_of_arrays->{$key} eq 'ARRAY' and
@{$hash_of_arrays->{$key}}) {
# data to process
@{$hash_of_calculations->{$key}}{'mean','std_dev'} =
(mean($hash_of_arrays->{$key}), dev($hash_of_arrays->{$key}));
  }
  else {
 # no data to process
 @{$hash_of_calculations->{$key}}{'mean','std_dev'} = ();
  }
}
for my $key (sort { $hash_of_calculations->{$a}->{'mean'} <=>
$hash_of_calculations->{$b}->{'mean'} } keys %hash_of_calculations) {
  print "Key: $key\n";
  print "Mean: $hash_of_calculations->{$key}->{'mean'}\n";
  print "Std Dev: $hash_of_calculations->{$key}->{'std_dev'}\n";
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




A better way.

2005-08-02 Thread Dan Klose
Hello Everyone.

I have the following code:


### CODE BLOCK ###

my %hash_of_arrays2;

for (keys %hash_of_arrays) {
  my @array_of_data = exists($hash_of_arrays{$_})
[EMAIL PROTECTED]
  :();

  my $mean = mean([EMAIL PROTECTED]); #GET MEAN
  my $std_dev = dev([EMAIL PROTECTED]); #GET STANDARD DEV

  push @{$hash_of_arrays2{$_}}, $mean;
  push @{$hash_of_arrays2{$_}}, $std_dev;
}

for (sort {$hash_of_arrays2{$a}[0] <=> $hash_of_arrays2{$b}[0]} 
 keys %hash_of_arrays2) {

  print "$_, $hash_of_arrays2{$_}[0], $hash_of_arrays2{$_}[1]\n";
}

### END OF CODE ###

If anyone has the time could you please show me ways of shortening this
code e.g. eliminating the second for block (integration into the
previous block) and any other tips / tricks.

There are no other people here that code perl and so I get no
advice/feedback on how to improve my scripts.

Thanks in advance.

Dan.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: HoH is there a better way?

2004-11-10 Thread Richard Kofler
Miguel Santinho wrote:
> 
> On Wed, 10 Nov 2004 00:04:12 -0600
> "Charles K. Clarkson" <[EMAIL PROTECTED]> wrote:
> 
> > my @headers = split ' ', ;
> 
> This way, if tomorrow you have some data like:
> 
> extents  nptot
>   51671035
>  2223412520365
> 
> you'll be in troubles, right?
> 

[ ... snip ... ]

For a generic app this risk is there, and maybe
substr is a save way to go, TMMV it depends
heavily on output processing/formation of the
predecessor in the pipeline.

But for the context in which I use the script
there is a maximum for the values of each
column. 

In my original posting the __DATA__ section
is from live output, only object names are
made neutral via script.
Sorry that the lines wrapped ...

> my @tables;
> while () {
> my %table;
> @table{ @headers } = split;
  ^^^
  I love this part! Looks like magic to me :-)

Indeed, this is a fascinating functionality of Perl!
I found it reading up about hash slices and array slices,
see the commented lines labelled xmpl in my original posting


dic_k
-- 
Richard Kofler
SOLID STATE EDV
Dienstleistungen GmbH
Vienna/Austria/Europe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: HoH is there a better way?

2004-11-10 Thread Charles K. Clarkson
Miguel Santinho (Simplicidade.com) <> wrote:

: On Wed, 10 Nov 2004 00:04:12 -0600
: "Charles K. Clarkson" <[EMAIL PROTECTED]> wrote:
: 
: : my @headers = split ' ', ;
: 
: This way, if tomorrow you have some data like:
: 
: extents  nptot
:   51671035
:  2223412520365
: 
: you'll be in troubles, right?

Correct.

: : my @tables;
: : while () {
: : my %table;
: : @table{ @headers } = split;
:   ^^^
:   I love this part! Looks like magic to me :-)


[bows] Thank you, thank you, I'll be here all week!


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: HoH is there a better way?

2004-11-10 Thread Miguel Santinho (Simplicidade.com)
On Wed, 10 Nov 2004 00:04:12 -0600
"Charles K. Clarkson" <[EMAIL PROTECTED]> wrote:
 
> my @headers = split ' ', ;

This way, if tomorrow you have some data like:

extents  nptot
  51671035
 2223412520365

you'll be in troubles, right?

 
> my @tables;
> while () {
> my %table;
> @table{ @headers } = split;
  ^^^
  I love this part! Looks like magic to me :-)

> push @tables, \%table;
> }
> 
> print Dumper [EMAIL PROTECTED];



pgpHCtOtF7IMY.pgp
Description: PGP signature


Re: HoH is there a better way?

2004-11-10 Thread Richard Kofler
Gunnar Hjalmarsson wrote:
> 
> Gunnar Hjalmarsson wrote:
> > You may want to remove the field names from the database, to avoid the
> > need to test for them at each iteration.
> 
> Optionally you can extract the field names from the first line of the
> database rather than hardcode them:
> 
>  sub tabinfo_hash {
>  my @elems = ( split ' ',  )[1..6];
>  my %tih;
>  while () {
>  ( my $table, my @vals) = split or next;
>  @{ $tih{$table} }{ @elems } = @vals;
>  last if $. > 10;
>  }
>  \%tih;
>  }
> 
> TMTOWTDI :)
> 
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl

Thank you for the refactoring. Seems it is time for me to
get rid of my FORTRAN II habits :)

dic_k
-- 
Richard Kofler
SOLID STATE EDV
Dienstleistungen GmbH
Vienna/Austria/Europe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: HoH is there a better way?

2004-11-10 Thread Richard Kofler
"Simplicidade.com" wrote:
> 
> Probably this is not better and it's not what you want.
> Take it as an alternative ;-)

I *need* the table name as key. I am pretty sure, that
any handcoded technique of search for the respective table 
will be considerably slower than picking out an element from
a hash.
 
[ ... AoH approach snipped ... ]> 
> # To get the 'big picture':
> use Data::Dumper;
> print Dumper [EMAIL PROTECTED];

Thank you for pointing me to Data::Dumper!
A very valuable hint, indeed.

dic_k
-- 
Richard Kofler
SOLID STATE EDV
Dienstleistungen GmbH
Vienna/Austria/Europe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: HoH is there a better way?

2004-11-09 Thread Charles K. Clarkson
Simplicidade.com <[EMAIL PROTECTED]> wrote:

: Probably this is not better and it's not what you want.
: Take it as an alternative ;-)
: 
: It's an Array of Hashes.
: It gets the column headers from the first row of __DATA__.
: When you have fixed length columns 'unpack' is a good choice.
: For this example I'm not using __END__ at the end of __DATA__
: :-) 
: 
: ##
: 
: my (@AoH, @headers);
: while () {
:   my %temp;

Define just before you use it or on the first use. Not at the
top. Avoid variables named "temp".


:   my @temp = unpack("A24 A7 A11 A11 A11 A10 A6", $_ );
:   $_ =~s/^\s+// foreach @temp;

split would probably be easier to maintain. Read up on its
special cases in perlfunc.


:   if ( [EMAIL PROTECTED] ) {
:   @headers = @temp

Why not do the header pass outside the loop?


:   } else {
:   $temp{$headers[$_]} = $temp[$_] for ( 0 .. $#temp);

A hash slice is neater and faster. This would have been
the correct scope for %temp.

:   push @AoH, \%temp;
:   }
: }


my @headers = split ' ', ;

my @tables;
while () {
my %table;
@table{ @headers } = split;
push @tables, \%table;
}

print Dumper [EMAIL PROTECTED];


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: HoH is there a better way?

2004-11-09 Thread Gunnar Hjalmarsson
Gunnar Hjalmarsson wrote:
You may want to remove the field names from the database, to avoid the 
need to test for them at each iteration.
Optionally you can extract the field names from the first line of the 
database rather than hardcode them:

sub tabinfo_hash {
my @elems = ( split ' ',  )[1..6];
my %tih;
while () {
( my $table, my @vals) = split or next;
@{ $tih{$table} }{ @elems } = @vals;
last if $. > 10;
}
\%tih;
}
TMTOWTDI :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: HoH is there a better way?

2004-11-09 Thread Gunnar Hjalmarsson
Richard Kofler wrote:
My sub does, what I expect it to do, but somehow it does look
clumpsy to me, when compared to code from the knowing ones
in c.l.p.m  :)
Not sure why you say that. To me, it seems to be an appropriate approach.
I'd apreciate it very much, if someone could hint me into
better ways to do it.
You can use the $. variable instead of the separate $icnt counter 
(provided that you accept that possible blank lines get included...).

You may want to remove the field names from the database, to avoid the 
need to test for them at each iteration.

You can use the return value from the split() operation instead of 
testing the length of respective line.

chomp()ing is redundant when you use split() that way.
So, this is a shorter version of the function:
sub tabinfo_hash {
my @elems = qw/ extents nptot npused npdata nrows rsize /;
my %tih;
while () {
( my $table, my @vals) = split or next;
@{ $tih{$table} }{ @elems } = @vals;
last if $. > 10;
}
\%tih;
}
And there is one main question left:
Is HoH appropriate for what I do, or is HoA a better way to go.
A HoH allows for clearer code IMO.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: HoH is there a better way?

2004-11-09 Thread Simplicidade.com

Probably this is not better and it's not what you want.
Take it as an alternative ;-)

It's an Array of Hashes.
It gets the column headers from the first row of __DATA__.
When you have fixed length columns 'unpack' is a good choice.
For this example I'm not using __END__ at the end of __DATA__ :-)

##

my (@AoH, @headers);
while () {
my %temp;
my @temp = unpack("A24 A7 A11 A11 A11 A10 A6", $_ );
$_ =~s/^\s+// foreach @temp;
if ( [EMAIL PROTECTED] ) {
@headers = @temp
} else {
$temp{$headers[$_]} = $temp[$_] for ( 0 .. $#temp);
push @AoH, \%temp;
}
}

# To get the 'big picture':
use Data::Dumper;
print Dumper [EMAIL PROTECTED];

# To get some elements from the first row:
print $AoH[0]->{'table'} , " : npdata = " , $AoH[0]->{'npdata'} ,
" AND npused = " , $AoH[0]->{'npused'} , "\n";

# Will print: table01 : npdata = 1653131 AND npused = 1653542

##

Have fun!

-- 

::::
::   Simplicidade.com ::
::   Consultoria em Tecnologias de Informação, Lda.   ::
::::
::   Rua António Onofre, 4D   ::
::   2870-220 Montijo - PORTUGAL  ::
::::
::   Tel./Fax: +351 21 231 01 51  ::
::::
::   [EMAIL PROTECTED]::
::   http://www.simplicidade.com  ::
::::



pgp2ASWcFvnCy.pgp
Description: PGP signature


HoH is there a better way?

2004-11-09 Thread Richard Kofler
I am on v5.8.5 / cygwin or v5.8.1 when on Linux or Solaris. 

I wrote a small sub to process output from a database utility
giving metainformation one line per table/index.

My sub does, what I expect it to do, but somehow it does look
clumpsy to me, when compared to code from the knowing ones
in c.l.p.m  :)

I'd apreciate it very much, if someone could hint me into
better ways to do it.

And there is one main question left:
Is HoH appropriate for what I do, or is HoA a better way to go.
After all I use this sub very much like a lookup table, much
like in the main:: of the code further down

Here is what I've got so far
(pasted after successful test)

#!/usr/bin/perl

use warnings;
use strict;
use diagnostics;

# testscript showing use of hoh

# RK 20041109 V01 initial version

sub tabinfo_hash {
# t_info file into hash tih
#
# Input
#
# table   extents  nptot npused
npdata  nrows rsize
# table1516710351653542   
1653131   3966830678


my @elems = qw/ extents nptot npused npdata nrows rsize /;

my %tih;
my $icnt = 0;
while () {
##xmpl: my @players = qw/ barney fred dino /;
##xmpl: my @bowling_scores = (195, 205, 30);
##xmpl: @score{ @players } = @bowling_scores;
 
chomp;
next if (length == 0);
next if ( /nptot\s+npused/ );
( my $table, my @vals) = split;
@{ $tih{$table} }{ @elems } = @vals;
$icnt++;
last if ($icnt > 10);
}
return \%tih;
}


my $ref_tih = tabinfo_hash;

print "table01/npdata: $ref_tih->{table01}{npdata}\n";
print "table02/npused: $ref_tih->{table02}{npused}\n";

__DATA__
table   extents  nptot npused npdata 
nrows rsize
table01   5167103516535421653131  
3966830678
table02  22   12520365   12513173   12509883  
12509883  1968
table03  10 112745 112680 
0  0  1968
table04   1 467507 465955 
0  0   277
table05   4 338890 338581 
0  0   114
table06   1 223580 223293 
0  0   108
table07   2117949911202341119956  
12318902   168
table08   1512122121  
240195
table09   1 68 21 
0  095
table10   1  65512  35431  35422
212530   295
table11   2  81892  80881  80860   
242474262
table12   1   5017   4915 
0  0   376
index01   1  48308  48068 
0  0   304
index02   2   8432   8397 
0  0   376
table13   1  65512  10162   4958  
4958  1983
table14   1 262098  58452  15572 
15576  2592
table15   1 131041  97083  97058   
592043129
index03   1197  5 
0  0   305
index04   1   4442   4386 
0  027
index05   1   1318973 
0  0   149
__END__


Resulting output is:
$ ./process_tabinfo_V01_dos.pl
table01/npdata: 1653131
table02/npused: 12513173


Thank you for any help
dic_k
-- 
Richard Kofler
SOLID STATE EDV
Dienstleistungen GmbH
Vienna/Austria/Europe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Is there a better way to?

2003-10-14 Thread Rob Dixon
Christopher Lyon wrote:
>
> From: simran [mailto:[EMAIL PROTECTED]
> >
> > On Tue, 2003-10-14 at 13:59, Christopher Lyon wrote:
> >
> > > I have a line of text that I want to pull an e-mail address
> > > out from. Is this the best way to pull that information from
> > > that line?
> > >
> > > 
> > > $user = 'From: "First Last Name" <[EMAIL PROTECTED]>';
> > >
> > > @addy = split(/ > > chop $addy[1];
> > > 
> > >
> > >
> > > Also, how do you handle if the email is in brackets like so?
> > >
> > > $user = 'From: "First Last Name" [EMAIL PROTECTED]';
> > >
> >
> > the cpan module:
> >
> > http://search.cpan.org/~miyagawa/Email-Find-0.09/lib/Email/Find.pm
> >
> > might come in handy...
>
> I have given that a try and it doesn't work all that great. It
> seems to be more suited for the To or CC fields and not the from.

What's your problem Christopher? It works fine with the data you've
shown. See below.

Cheers,

Rob



use strict;
use warnings;

use Email::Find;

my $user = 'From: "First Last Name" <[EMAIL PROTECTED]>';

foreach my $user (
'From: "First Last Name" <[EMAIL PROTECTED]>',
'From: "First Last Name" [EMAIL PROTECTED]' ) {

  find_emails ($user, sub {
my $email = pop @_;
print $email, "\n";
$email;
  });
}

** OUTPUT **

[EMAIL PROTECTED]
[EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Is there a better way to?

2003-10-13 Thread Christopher Lyon
I have given that a try and it doesn't work all that great. It seems to
be more suited for the To or CC fields and not the from.



> -Original Message-
> From: simran [mailto:[EMAIL PROTECTED]
> Sent: Monday, October 13, 2003 9:12 PM
> To: Christopher Lyon
> Cc: [EMAIL PROTECTED]
> Subject: Re: Is there a better way to?
> 
> the cpan module:
> 
> http://search.cpan.org/~miyagawa/Email-Find-0.09/lib/Email/Find.pm
> 
> might come in handy...
> 
> 
> On Tue, 2003-10-14 at 13:59, Christopher Lyon wrote:
> > I have a line of text that I want to pull an e-mail address out
from. Is
> > this the best way to pull that information from that line?
> >
> > 
> > $user = 'From: "First Last Name" <[EMAIL PROTECTED]>';
> >
> > @addy = split(/ > chop $addy[1];
> > 
> >
> >
> > Also, how do you handle if the email is in brackets like so?
> >
> > $user = 'From: "First Last Name" [EMAIL PROTECTED]';
> >
> >
> >
> 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Is there a better way to?

2003-10-13 Thread simran
the cpan module:

http://search.cpan.org/~miyagawa/Email-Find-0.09/lib/Email/Find.pm

might come in handy... 


On Tue, 2003-10-14 at 13:59, Christopher Lyon wrote:
> I have a line of text that I want to pull an e-mail address out from. Is
> this the best way to pull that information from that line?
> 
> 
> $user = 'From: "First Last Name" <[EMAIL PROTECTED]>';
> 
> @addy = split(/ chop $addy[1];
> 
> 
> 
> Also, how do you handle if the email is in brackets like so?
> 
> $user = 'From: "First Last Name" [EMAIL PROTECTED]';
> 
> 
> 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Is there a better way to?

2003-10-13 Thread Christopher Lyon
I have a line of text that I want to pull an e-mail address out from. Is
this the best way to pull that information from that line?


$user = 'From: "First Last Name" <[EMAIL PROTECTED]>';

@addy = split(/


Also, how do you handle if the email is in brackets like so?

$user = 'From: "First Last Name" [EMAIL PROTECTED]';






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: looking for a better way...

2003-08-14 Thread Pinku Bhatnagar
Hey Jerry,

I have a one quick solution for you.

str = "\"q4171\",\"(08/11/03 23:30:48)\",\"\"";
@array = split(/,/,$str);
foreach (@array)
{
s/\"//g ;
}
HTH
Pinku
Jerry Preston wrote:
Hi!,

I am trying to breakdown this line:

"q4171","(08/11/03 23:30:48)",""

with  ( @data ) = split /[,|\"]/;#"

but I get many parts of the array that are empty.

All I want is in between the "'s.

Thanks,

Jerry



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


looking for a better way...

2003-08-14 Thread Jerry Preston
Hi!,

I am trying to breakdown this line:

"q4171","(08/11/03 23:30:48)",""

with  ( @data ) = split /[,|\"]/;#"

but I get many parts of the array that are empty.

All I want is in between the "'s.

Thanks,

Jerry


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: looking for a better way...

2003-08-14 Thread Pinku Bhatnagar
hi Jerry,

On second thought, I have a better solution for you.

$str = "\"q4171\",\"(08/11/03 23:30:48)\",\"\"";
@array = $str =~ /"([^"]*)"/g;
HTH
Pinku
Jerry Preston wrote:

Hi!,

I am trying to breakdown this line:

"q4171","(08/11/03 23:30:48)",""

with  ( @data ) = split /[,|\"]/;#"

but I get many parts of the array that are empty.

All I want is in between the "'s.

Thanks,

Jerry



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: looking for a better way...

2003-08-14 Thread NYIMI Jose (BMB)
"q4171","(08/11/03 23:30:48)",""
Makes me thing of CSV (comma separated value).
You may need to check CPAN for CSV module if
You have to parse a lot of such string from a given file.

José.

-Original Message-
From: Jerry Preston [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 12, 2003 10:38 AM
To: [EMAIL PROTECTED]
Subject: looking for a better way...


Hi!,

I am trying to breakdown this line:

"q4171","(08/11/03 23:30:48)",""

with  ( @data ) = split /[,|\"]/;#"

but I get many parts of the array that are empty.

All I want is in between the "'s.

Thanks,

Jerry




 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: looking for a better way...

2003-08-14 Thread Jeff 'japhy' Pinyan
On Aug 12, Jerry Preston said:

>I am trying to breakdown this line:
>
>"q4171","(08/11/03 23:30:48)",""
>
>with  ( @data ) = split /[,|\"]/;#"

Either use the Text::CSV module from CPAN (or perhaps Text::CSV_XS), or
else use a regex like the following:

  @fields = $str =~ m{ " [^"]* " | [^,]+ }xg;

If you also want to strip quotes, you can do:

  @fields = map { s/^"// and s/"$// } $str =~ m{ ... }xg;

(Just fill the regex in.)

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Is there a better way?

2003-07-23 Thread denis
On Tue, 22 Jul 2003, Rob Dixon wrote:

> [EMAIL PROTECTED] wrote:
> > I know I'm missing something here, but this code just looks to me
> > like I shloud be doing it a better way..
> >
> > Any ideas?
> >
> >
> > # -N
> > print "Number of Hosts?  ";
> > # get user input and strip off "CR-LF"
> > chomp($n=<>);
> > $intel_num_hosts = join (" ", "-N",$n);
> > # if user did not enter a value, dont put the "-N" in
> > if ($n eq ""){ $intel_num_hosts = ""}
> >
> > # -n
> > print "Number of processes?  ";
> > chomp($n=<>);
> > $intel_num_procs = join (" ", "-n",$n);
> > if ($n eq ""){ $intel_num_procs = ""}
> 
> 
>   use strict;
>   use warnings;
> 
>   my $n;
>   my $intel_num_hosts = '';
>   my $intel_num_procs = '';
> 
>   {
> print "Number of Hosts?  ";
> chomp ($n = <>);
> redo if $n =~ /\D/;
>   }
>   $intel_num_hosts = "-N $n" if $n;
> 
>   {
> print "Number of processes?  ";
> chomp ($n = <>);
> redo if $n =~ /\D/;
>   }
>   $intel_num_procs = "-n $n" if $n;
> 
> 
> 
> HTH,
> 
> Rob
> 


Thanks Rob for the code bit.. Also thanks to all of the others that 
replied. 

Denis


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Is there a better way?

2003-07-22 Thread Rob Dixon
[EMAIL PROTECTED] wrote:
> I know I'm missing something here, but this code just looks to me
> like I shloud be doing it a better way..
>
> Any ideas?
>
>
> # -N
> print "Number of Hosts?  ";
> # get user input and strip off "CR-LF"
> chomp($n=<>);
> $intel_num_hosts = join (" ", "-N",$n);
> # if user did not enter a value, dont put the "-N" in
> if ($n eq ""){ $intel_num_hosts = ""}
>
> # -n
> print "Number of processes?  ";
> chomp($n=<>);
> $intel_num_procs = join (" ", "-n",$n);
> if ($n eq ""){ $intel_num_procs = ""}


  use strict;
  use warnings;

  my $n;
  my $intel_num_hosts = '';
  my $intel_num_procs = '';

  {
print "Number of Hosts?  ";
chomp ($n = <>);
redo if $n =~ /\D/;
  }
  $intel_num_hosts = "-N $n" if $n;

  {
print "Number of processes?  ";
chomp ($n = <>);
redo if $n =~ /\D/;
  }
  $intel_num_procs = "-n $n" if $n;



HTH,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Is there a better way?

2003-07-22 Thread Jeff 'japhy' Pinyan
On Jul 22, Kevin Pfeiffer said:

>In article <[EMAIL PROTECTED]>,
>[EMAIL PROTECTED] wrote:
>
>>
>> I know I'm missing something here, but this code just looks to me like I
>> shloud be doing it a better way..
>>
>> Any ideas?
>
>my $intel_num_hosts = '';
>my $num_hosts = get_input("Number of hosts? ");
>$intel_num_hosts = join (" ", "-N", $num_hosts) if $num_hosts;

That still seems long-winded to me.  I'd write:

  my $n_hosts = get_input("Number of hosts? ");
  my $opt_hosts = $n_hosts ? "-N $n_hosts" : "";

  my $n_procs = get_input("Number of processes? ");
  my $opt_procs = $n_procs ? "-n $n_procs" : "";

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Is there a better way?

2003-07-22 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Kevin Pfeiffer wrote:
[...]
>   unless ($input =~ /^[^\D]+/ or $input eq '') {

While messing around with the valid '' input problem I see I obfuscated the 
regex. I think this will do just fine:

unless ($input =~ /^\d+/ or $input eq '') {


-- 
Kevin Pfeiffer
International University Bremen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Is there a better way?

2003-07-21 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] wrote:

> 
> I know I'm missing something here, but this code just looks to me like I
> shloud be doing it a better way..
> 
> Any ideas?
> 
> 
> # -N
> print "Number of Hosts?  ";
> # get user input and strip off "CR-LF"
> chomp($n=<>);
> $intel_num_hosts = join (" ", "-N",$n);
> # if user did not enter a value, dont put the "-N" in
> if ($n eq ""){ $intel_num_hosts = ""}
> 
> # -n
> print "Number of processes?  ";
> chomp($n=<>);
> $intel_num_procs = join (" ", "-n",$n);
> if ($n eq ""){ $intel_num_procs = ""}

Here's my version (corrections, improvements welcome); it's longer (not sure 
that's what you wanted), but it does a little error-checking...

my $intel_num_hosts = '';
my $num_hosts = get_input("Number of hosts? ");
$intel_num_hosts = join (" ", "-N", $num_hosts) if $num_hosts;

my $intel_num_procs = '';
my $num_procs = get_input("Number of processes? ");
$intel_num_procs = join (" ", "-n", $num_procs) if $num_procs;

sub get_input {
   my $prompt = shift;
   my $input =''; my $err_cnt = 0;
   {
  print $prompt;
  chomp($input = );
  unless ($input =~ /^[^\D]+/ or $input eq '') {
 die "Invalid input, exiting\n" if ++$err_cnt > 2;
 redo;
  }
   }
   return $input;
}

-K

-- 
Kevin Pfeiffer
International University Bremen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Is there a better way?

2003-07-21 Thread denis

I know I'm missing something here, but this code just looks to me like I 
shloud be doing it a better way..

Any ideas?


# -N
print "Number of Hosts?  ";
# get user input and strip off "CR-LF"
chomp($n=<>);
$intel_num_hosts = join (" ", "-N",$n);
# if user did not enter a value, dont put the "-N" in
if ($n eq ""){ $intel_num_hosts = ""}

# -n
print "Number of processes?  ";
chomp($n=<>);
$intel_num_procs = join (" ", "-n",$n);
if ($n eq ""){ $intel_num_procs = ""}

Thanks

Denis













-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread R. Joseph Newton
Rob Dixon wrote:

> > Unless the $target variable was meant simply to decide on a return, it makes more
> > sense to assign its value--one task, one line, and check it for validity--another 
> > task
> > entirely, on a line of its own.
>
> So presumably you're against
>
> while ( my $line =  ) {
> :
> }
>
> on the same grounds? :)

Only in cases where one is having trouble sorting out whether problems are arising 
from the assignment, or some aspect of the validation statement.  It doesn't do any 
harm to take the extra line.

>
>
> > The only thing it lacked was a meaningful return value. Since the getTarget 
> > function
> > provided enough information to decide in favor of an early exit, this information
> > should probably be passed on more explicitly, perhaps just by returning 0 rather
> > than undef.
>
> I might buy
>
> ... this information could /possibly/ be passed on ...
>
> A simple
>
> return;
>
> is /explicitly/ not returning a value, which is fine. The fact that you get 'undef' 
> if you
> use the subroutine call as a value is irrelevant.
>
> I don't believe a subroutine should always return a value just because it /can/. That
> value is only useful if the calling code needs to behave differently depending on
> the action of the subroutine. More often than not there's simply no point in passing
> any value back to the calling code at all. Coding a return value that isn't used just
> makes you look for subtleties that aren't there, and can lead (with the 'single exit
> point' strategy) to the nightmare of dozens of subroutines which uselessly have a
> 'return 1' as their final statement. I do wish though that there was a better 
> distinction
> between returning control and returning a value. In Perl it's made slightly worse 
> because
> you can have both a 'return' without a value and a value without a 'return' (on the 
> last
> line of the subroutine).
>
> Cheers,
>
> Rob

Agreed.  The overall sense of the question, though, indicated to me that there is a 
lot going on in this function, and that it wouldn't hurt to provide any calling 
function with some indication of what went on inside.  If the caller has no use for 
the return falags, then it can call in a void context.  But this sense arises more 
from the apparent nature of the function than as a blanket rule.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Rob Dixon
R. Joseph Newton wrote:
> Paul Johnson wrote:
> > To my mind,
> >   return if $target eq "MAIN";
> > at the top of a sub is a lot more helpful than making me search all the
> > way down to the botttom to see if there is anything after the conditional.
> >
> > And it's probably a lot less likely that the next person to edit that sub
> > will goof up by adding something where it shouldn't be.
> >
> > Slavish devotion to the single exit point paradigm can produce some
> > wonderfully messy code, all scrunched up at the right of the screen.
> >
> > Then again, I probably wouldn't merge those two original lines either.
> >
> > --
> > Paul Johnson - [EMAIL PROTECTED]
> > http://www.pjcj.net
>
> Ditto--on both points.  The original formulation was just fine.

Brian Ling wrote:
>
> my $target = getTarget();
> If ( $target eq "MAIN" ) { return }
> #do lots of other stuff with value of target

I wouldn't disagree, except that it's the perfect place to use

return If $target eq "MAIN"

or

$target eq "MAIN" and return

to cut down on the furniture.

> Unless the $target variable was meant simply to decide on a return, it makes more
> sense to assign its value--one task, one line, and check it for validity--another 
> task
> entirely, on a line of its own.

So presumably you're against

while ( my $line =  ) {
:
}

on the same grounds? :)

> The only thing it lacked was a meaningful return value. Since the getTarget function
> provided enough information to decide in favor of an early exit, this information
> should probably be passed on more explicitly, perhaps just by returning 0 rather
> than undef.

I might buy

... this information could /possibly/ be passed on ...

A simple

return;

is /explicitly/ not returning a value, which is fine. The fact that you get 'undef' if 
you
use the subroutine call as a value is irrelevant.

I don't believe a subroutine should always return a value just because it /can/. That
value is only useful if the calling code needs to behave differently depending on
the action of the subroutine. More often than not there's simply no point in passing
any value back to the calling code at all. Coding a return value that isn't used just
makes you look for subtleties that aren't there, and can lead (with the 'single exit
point' strategy) to the nightmare of dozens of subroutines which uselessly have a
'return 1' as their final statement. I do wish though that there was a better 
distinction
between returning control and returning a value. In Perl it's made slightly worse 
because
you can have both a 'return' without a value and a value without a 'return' (on the 
last
line of the subroutine).

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread R. Joseph Newton
Paul Johnson wrote:

> R. Joseph Newton said:
>
> >The only thing it
> > lacked was a meaningful return value.  Since the getTarget function
> > provided enough information to decide in favor of an early exit, this
> > information should probably be passed on more explicitly, perhaps just by
> > returning 0 rather than undef.
>
> Just to pick nits, I think that a plain return here is absolutely correct.
>  Or, at least it is in the general case, given that we know nothing about
> the return values of this particular function.
>
> The reason?  If you return 0 or an explicit undef, and then call the
> function in list context, you will have returned a true value, a list with
> one element.  If you just return, then in list context the return value
> will be an empty list, which is a false value.  Calling a function in list
> context can occur more often that you might imagine, and so I recommend
> this as a good habit to get into.
>
> --
> Paul Johnson - [EMAIL PROTECTED]

Good point, Paul.  I forget that Perl has that feature.  I mean, I use it to load 
variables from existing functions, but I seriously doubt that I would ever return 
anything other than  scalar from a function.  I value the funnel model for functions.  
I tend to use reference parameters for any function whose specification would not be 
satisfied with a discrete scalar.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Paul Johnson
R. Joseph Newton said:

>The only thing it
> lacked was a meaningful return value.  Since the getTarget function
> provided enough information to decide in favor of an early exit, this
> information should probably be passed on more explicitly, perhaps just by
> returning 0 rather than undef.

Just to pick nits, I think that a plain return here is absolutely correct.
 Or, at least it is in the general case, given that we know nothing about
the return values of this particular function.

The reason?  If you return 0 or an explicit undef, and then call the
function in list context, you will have returned a true value, a list with
one element.  If you just return, then in list context the return value
will be an empty list, which is a false value.  Calling a function in list
context can occur more often that you might imagine, and so I recommend
this as a good habit to get into.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread R. Joseph Newton
Paul Johnson wrote:

> To my mind,
>   return if $target eq "MAIN";
> at the top of a sub is a lot more helpful than making me search all the
> way down to the botttom to see if there is anything after the conditional.
>
> And it's probably a lot less likely that the next person to edit that sub
> will goof up by adding something where it shouldn't be.
>
> Slavish devotion to the single exit point paradigm can produce some
> wonderfully messy code, all scrunched up at the right of the screen.
>
> Then again, I probably wouldn't merge those two original lines either.
>
> --
> Paul Johnson - [EMAIL PROTECTED]
> http://www.pjcj.net

Ditto--on both points.  The original formulation was just fine.  Unless the $target 
variable was meant simply to decide on a return, it makes more sense to assign its 
value--one task, one line, and check it for validity--another task entirely, on a line 
of its own.  The only thing it lacked was a meaningful return value.  Since the 
getTarget function provided enough information to decide in favor of an early exit, 
this information should probably be passed on more explicitly, perhaps just by 
returning 0 rather than undef.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread R. Joseph Newton
Rob Richardson wrote:

> Stefan,
>
> Personally, I'd prefer:
>
> if (target ne "MAIN")
> {
>#do lots of other stuff
> }
>
> I think general programming practice discourages multiple return points
> in subroutines.
>
> RobR

I disagree.  While one should certainly exercise care when making an early return, and 
clean up any external links that may have been created, such constructs can make for 
very clear and efficient code.  Usually, I do it first thing after taking arguments.  
It just makes sense, before you jump into a process, to see if you really need to do 
the process at all.  Among other things, early returns act as very elegant handlers 
for the stopping cases in recursive functions.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Rob Dixon
Paul Johnson wrote:
> Rob Dixon said:
> > "Rob Richardson" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > > Stefan,
> > >
> > > Personally, I'd prefer:
> > >
> > > if (target ne "MAIN")
> > > {
> > >#do lots of other stuff
> > > }
> > >
> > > I think general programming practice discourages multiple return points
> > > in subroutines.
> >
> > Yes, and it's no more dangerous than multiple 'last' statements in loops.
>
> To my mind,
>   return if $target eq "MAIN";
> at the top of a sub is a lot more helpful than making me search all the
> way down to the botttom to see if there is anything after the conditional.
>
> And it's probably a lot less likely that the next person to edit that sub
> will goof up by adding something where it shouldn't be.
>
> Slavish devotion to the single exit point paradigm can produce some
> wonderfully messy code, all scrunched up at the right of the screen.

It's one of the more useless dogma to have come out of the industry.
As you say it's easy to create unreadable code through being tied to
only a single 'return', and I'd say it's just about as easy to write nonsense
by scattering returns through a subroutine with impunity. Any rule
to get around the problem has to be much less simplistic.

It's the same problem as the anti 'goto' camp. I would say that gotos
are fine, but labels are a real problem because you can use them
to jump into and out of scopes and pop stack frames as you wish.

'next', 'last', 'redo', 'return', 'exit' and subroutine calls are all gotos,
except that they're not allowed labels in the general sense that
'goto' is. The point they refer to is a well defined and sensible
place to pass control to within normal programming practice.

> Then again, I probably wouldn't merge those two original lines either.

That's another one for another day :)

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Paul Johnson

Rob Dixon said:

>
> "Rob Richardson" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Stefan,
>>
>> Personally, I'd prefer:
>>
>> if (target ne "MAIN")
>> {
>>#do lots of other stuff
>> }
>>
>> I think general programming practice discourages multiple return points
>> in subroutines.
>
> Yes, and it's no more dangerous than multiple 'last' statements in loops.

To my mind,
  return if $target eq "MAIN";
at the top of a sub is a lot more helpful than making me search all the
way down to the botttom to see if there is anything after the conditional.

And it's probably a lot less likely that the next person to edit that sub
will goof up by adding something where it shouldn't be.

Slavish devotion to the single exit point paradigm can produce some
wonderfully messy code, all scrunched up at the right of the screen.

Then again, I probably wouldn't merge those two original lines either.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Rob Dixon
Brian Ling wrote:
> Thanks for that, I had not released you could effectively use the
> getTarget() return value twice :-)
>
> > well this works:
> > return if 'MAIN' eq (my $target = getTarget());
>
> > /Stefan


Personally, I prefer:

( my $target = getTarget() ) eq 'MAIN' and return;

as I believe that the declaration should always be at the beginning
of the line. If that's not possible with the construct you need
then there's nothing lost by doing

my $target;
return if 'MAIN' eq ( $target = getTarget() );

Cheers,

Rob





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Rob Dixon

"Rob Richardson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Stefan,
>
> Personally, I'd prefer:
>
> if (target ne "MAIN")
> {
>#do lots of other stuff
> }
>
> I think general programming practice discourages multiple return points
> in subroutines.

Yes, and it's no more dangerous than multiple 'last' statements in loops.

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: A better way

2003-04-03 Thread Brian Ling
Thanks for that, I had not released you could effectively use the
getTarget() return value twice :-) 

>well this works:
>return if 'MAIN' eq (my $target = getTarget());

>/Stefan




BBCi at http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain 
personal views which are not the views of the BBC unless specifically 
stated.
If you have received it in error, please delete it from your system, do 
not use, copy or disclose the information in any way nor act in 
reliance on it and notify the sender immediately. Please note that the 
BBC monitors e-mails sent or received. Further communication will 
signify your consent to this.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Rob Richardson
Stefan,

Personally, I'd prefer:

if (target ne "MAIN")
{
   #do lots of other stuff
}

I think general programming practice discourages multiple return points
in subroutines.

RobR



__
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: A better way

2003-04-03 Thread Stefan Lidman
Brian Ling wrote:
> 
> Hi List,
> 
> I have the following bit of code, that works but doesn't feel like the
> best way, can anyone think of a better neater answer maybe a one liner?
> 
> my $target = getTarget();
> If ( target eq "MAIN" ) { return }
> #do lots of other stuff with value of target

well this works:
return if 'MAIN' eq (my $target = getTarget());

/Stefan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



A better way

2003-04-03 Thread Brian Ling
Hi List,

I have the following bit of code, that works but doesn't feel like the
best way, can anyone think of a better neater answer maybe a one liner?

my $target = getTarget();
If ( target eq "MAIN" ) { return }
#do lots of other stuff with value of target

Thanks 

Brian






BBCi at http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain 
personal views which are not the views of the BBC unless specifically 
stated.
If you have received it in error, please delete it from your system, do 
not use, copy or disclose the information in any way nor act in 
reliance on it and notify the sender immediately. Please note that the 
BBC monitors e-mails sent or received. Further communication will 
signify your consent to this.



Re: looking for a better way, a perl way

2003-03-06 Thread John W. Krahn
Jerry Preston wrote:
> 
> Hi!

Hello,

> I am looking for way to reduce the following code,  a better way, a perl
> way.  Any ideas?
> 
>   while ( my ( $Site, $Description, $Part_Number, $Part_Serial_Number, $Qty,
> $RMA_Number, $Customer_Contac, $RMA_Date, $Part_Rec ) = $sth->fetchrow()) {
> #  while ( $data ) = $sth->fetchrow()) {
> $l = length( $Site );
> if( $l != 5 ) {
>   $s = substr( "", 0, 5 - $l );
>   $Site .= $s;
> }

  $Site = sprintf '%-5s ', $Site;


> $l = length( $Description );
> if( $l > 15 ) {
>   $Description = substr( $Description, 0, 14 );
> }elsif( $l != 15 ) {
>   $s = substr( " ", 0, 14 - $l );
>   $Description .= $s;
> }

  $Description = sprintf '%-14.14s ', $Description;


> $l = length( $Part_Number );
> if( $l > 15 ) {
>   $Part_Number = substr( $Part_Number, 0, 14 );
> }elsif( $l != 15 ) {
>   $s = substr( " ", 0, 14 - $l );
>   $Part_Number .= $s;
> }

$Part_Number = sprintf '%-14.14s ', $Part_Number;


> $l = length( $Part_Serial_Number );
> if( $l > 10 ) {
>   $Part_Serial_Number = substr( $Part_Serial_Number, 0, 9 );
> }elsif( $l != 1 ) {
>   $s = substr( " ", 0, 9 - $l );
>   $Part_Serial_Number .= $s;
> }

  $Part_Serial_Number = sprintf '%-9.9s ', $Part_Serial_Number;


> $l = length( $Qty );
> if( $l > 3 ) {
>   $Qty = substr( $Qty, 0, 2 );
> }elsif( $l != 1 ) {
>   $s = substr( " ", 0, 3 - $l );
>   $Qty .= $s;
> }

  $Qty = sprintf '%-2.2s ', $Qty;


> if( $Site !~ /test/i ) {
>   $_ = "$Site|$Description |$Part_Number |$Part_Serial_Number |$Qty
> |$RMA_Number |$Customer_Contact |$RMA_ Date |$Part_ Rec\n";
> #  print $_;
>   print FO $_;

local $_ = join( '|', $Site, $Description, $Part_Number,
$Part_Serial_Number, $Qty, $RMA_Number, $Customer_Contact, $RMA_ Date,
$Part_ Rec ) . "\n";
 #  print;
   print FO;


> }
>   }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: looking for a better way, a perl way

2003-03-06 Thread Bakken, Luke
Look at the sprintf function. Please!

> #  while ( $data ) = $sth->fetchrow()) {
> $l = length( $Site );
> if( $l != 5 ) {
>   $s = substr( "", 0, 5 - $l );
>   $Site .= $s;
> }

Does this do what you want?

$Site = sprintf '%-5s', $Site;

One liner:

C:\>perl -e"$Site = q(Foo); $Site = sprintf q(%-5s), $Site; print
qq('$Site'\n)"
'Foo  '

Luke

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: looking for a better way, a perl way

2003-03-06 Thread Rob Dixon
Hi Jerry.

"Jerry Preston" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi!
>
> I am looking for way to reduce the following code,  a better way, a
perl
> way.  Any ideas?

I think you've been overlooked a little because your post looks
very much like a 'please do my work for me' post, rather than
an 'I'm a beginner who's tried everything he can think of and
is still stuck' one. I'll give you the benefit of the doubt here
and offer a hint.

[snip]

> $l = length( $Description );
> if( $l > 15 ) {
>   $Description = substr( $Description, 0, 14 );
> }elsif( $l != 15 ) {
>   $s = substr( " ", 0, 14 - $l );
>   $Description .= $s;
> }

You're repeating this construct for every column in your database
row. Your intention is to force each field to a fixed length by
curtailing or space-padding it. (Although what you're actually
doing here is adjusting all strings to a length of 14 unless
they're already 15 characters long.) This is how to do that in
Perl:

$Description = sprintf "%-14.14", $Description;

But you need to write the whole thing a little more elegantly:
the field lengths should be in an array corresponding to the
list of field values from the row. And you shouldn't be
extracting the fields into named scalars unless the names
have relevance to your code - leave them as anonymous array
elements if that will suffice.

It would be nice if we could see your improved version when
it's done!

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



looking for a better way, a perl way

2003-03-05 Thread Jerry Preston
Hi!

I am looking for way to reduce the following code,  a better way, a perl
way.  Any ideas?

  while ( my ( $Site, $Description, $Part_Number, $Part_Serial_Number, $Qty,
$RMA_Number, $Customer_Contac, $RMA_Date, $Part_Rec ) = $sth->fetchrow()) {
#  while ( $data ) = $sth->fetchrow()) {
$l = length( $Site );
if( $l != 5 ) {
  $s = substr( "", 0, 5 - $l );
  $Site .= $s;
}
$l = length( $Description );
if( $l > 15 ) {
  $Description = substr( $Description, 0, 14 );
}elsif( $l != 15 ) {
  $s = substr( " ", 0, 14 - $l );
  $Description .= $s;
}

$l = length( $Part_Number );
if( $l > 15 ) {
  $Part_Number = substr( $Part_Number, 0, 14 );
}elsif( $l != 15 ) {
  $s = substr( " ", 0, 14 - $l );
  $Part_Number .= $s;
}

$l = length( $Part_Serial_Number );
if( $l > 10 ) {
  $Part_Serial_Number = substr( $Part_Serial_Number, 0, 9 );
}elsif( $l != 1 ) {
  $s = substr( " ", 0, 9 - $l );
  $Part_Serial_Number .= $s;
}

$l = length( $Qty );
if( $l > 3 ) {
  $Qty = substr( $Qty, 0, 2 );
}elsif( $l != 1 ) {
  $s = substr( " ", 0, 3 - $l );
  $Qty .= $s;
}


if( $Site !~ /test/i ) {
  $_ = "$Site|$Description |$Part_Number |$Part_Serial_Number |$Qty
|$RMA_Number |$Customer_Contact |$RMA_ Date |$Part_ Rec\n";
#  print $_;
  print FO $_;
}
  }

Thanks,

Jerry


Re: A better way, a perl way?

2003-01-23 Thread Jeff 'japhy' Pinyan
On Jan 22, david said:

>>   @data_ = map { (my $copy = $_) =~ s/^ //; $copy } @data;
>
>s/^ // for(@data_ = @data);

Sigh.  I usually do that.  I was a little slow on the idiom-uptake.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: A better way, a perl way?

2003-01-22 Thread david
Jeff 'Japhy' Pinyan wrote:

> 
> If you DON'T want that, you'd have to do:
> 
>   for (@data) {
> (my $copy = $_) =~ s/^ //;
> push @data_, $copy;
>   }
> 
> Or something to that effect.  Here's a one-liner:
> 
>   @data_ = map { (my $copy = $_) =~ s/^ //; $copy } @data;
>

a bit shorter:

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

my @data  = (' 123',' 456',' 789');
my @data_ = ();

s/^ // for(@data_ = @data);

print join('',@data),"\n",join('',@data_),"\n";

__END__

prints:

 123 456 789
123456789

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: A better way, a perl way?

2003-01-22 Thread Bob Showalter
Frank Wiles wrote:
>  .--[ Jerry Preston wrote (2003/01/22 at 11:59:14) ]--  |
>  |  I am looking for a better way, a perl way for the following:  |
>  |  foreach ( @data ) ) {
>  |s/^ //;
>  |$data_[ $jp++ ] = $_;
>  |  }
>  |
>  `-
> 
> I'm assuming you are wanting to remove all entries in @data that
> begin with a space, this will do it in one line:
> 
> @data = map( { if( $_ !~ s/^ //) { $_; } }, @data);

That doesn't compile. What are you trying to do?

Not sure why you're assuming that's what he wants, but if it is, wouldn't a
simple grep be the way to do it?

   @data = grep $_ !~ /^ /, @data;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: A better way, a perl way?

2003-01-22 Thread Frank Wiles
 .--[ Jerry Preston wrote (2003/01/22 at 11:59:14) ]--
 | 
 |  I am looking for a better way, a perl way for the following:
 |  
 |  foreach ( @data ) ) {
 |s/^ //;
 |$data_[ $jp++ ] = $_;
 |  }
 |  
 `-

I'm assuming you are wanting to remove all entries in @data that
begin with a space, this will do it in one line: 

@data = map( { if( $_ !~ s/^ //) { $_; } }, @data); 

 -
   Frank Wiles <[EMAIL PROTECTED]>
   http://frank.wiles.org
 -


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: A better way, a perl way?

2003-01-22 Thread Jeff 'japhy' Pinyan
On Jan 22, Jerry Preston said:

>I am looking for a better way, a perl way for the following:
>
>foreach ( @data ) ) {
>  s/^ //;
>  $data_[ $jp++ ] = $_;
>}

You do realize that you're modifying the elements in @data as well, right?
So that, unless $jp starts at some value other than 0, @data_ and @data
are exactly the same.

If you DON'T want that, you'd have to do:

  for (@data) {
(my $copy = $_) =~ s/^ //;
push @data_, $copy;
  }

Or something to that effect.  Here's a one-liner:

  @data_ = map { (my $copy = $_) =~ s/^ //; $copy } @data;

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




A better way, a perl way?

2003-01-22 Thread Jerry Preston
I am looking for a better way, a perl way for the following:

foreach ( @data ) ) {
  s/^ //;
  $data_[ $jp++ ] = $_;
}


I have seen a one liner using while, but I do not remember.

Thanks,

Jerry


Re: A better way to handle array index?

2002-10-21 Thread Jenda Krynicky
From: chris <[EMAIL PROTECTED]>
> I am looking for a less cryptic way to handle array index.
> 
> most cryptic
> $array[0]
> 
> better
> use constant NAME => 0;
> $array[NAME]

This all depends on what do you want to do with the data structure.
But most probably you do want to use a hash.

$hash{NAME}

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: A better way to handle array index?

2002-10-21 Thread Jenda Krynicky
From: "Johnstone, Colin" <[EMAIL PROTECTED]>

> for example I read my form variables into a hash for processing. 
> 
> I then reference them by the form fieldname.
> 
> #read STDIN, $PostData, $ENV{'CONTENT_LENGTH'};
> 
> #print "post data =$PostData";
> 
> #postdata will look like this
> #[EMAIL PROTECTED]&radAction=unsubscribe&rad
> #Format=html&Submit=Submit I need to extract from this string the
> #fields and their values
> my @fields = split( /\&/, $PostData);
> 
> ...

Please don't do this. The query/posted data parsing is not as simple 
as it seems. You are much safer if you 
use CGI;

Or maybe
use CGI::Deurl;

Both available from CPAN, CGI.pm should already be installed.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: A better way to handle array index?

2002-10-20 Thread Timothy Johnson
 
And if you're really stuck with using arrays, you can always:

my @bases = ();
my $first = 0;

$bases[$first] = 'who';

-Original Message-
From: Johnstone, Colin
To: 'chris'
Cc: '[EMAIL PROTECTED]'
Sent: 10/19/02 5:47 PM
Subject: RE: A better way to handle array index?

That would be a hash. (or an associative array)

for example I read my form variables into a hash for processing. 

I then reference them by the form fieldname.

#read STDIN, $PostData, $ENV{'CONTENT_LENGTH'};

#print "post data =$PostData";

#postdata will look like this
#[EMAIL PROTECTED]&radAction=unsubscribe&radFo
rmat=html&Submit=Submit
#I need to extract from this string the fields and their values
my @fields = split( /\&/, $PostData);

#Once extracted I write the fieldnames and their values to the formData
Hash
#the index is the fieldname from the form
foreach $_ ( @fields ){
  @data = split( /=/, $_ );
  $formData{$data[0]} = $data[1];
}

#This routine is used to check the values in the form data hash for
debugging purposes
# while(($k,$v)=each(%formData)){
#   print"$k => $v";
# }


# I access the values of the fields by calling them as below
# another name for a has is an associative array
# print "Email Address =".$formData{'txtEmailAddr'}."";
# print "Action =".$formData{'radAction'}."";
# print "Format =".$formData{'radFormat'}."";

-Original Message-
From: chris [mailto:chris@;home.com]
Sent: Sunday, October 20, 2002 10:40
To: [EMAIL PROTECTED]
Subject: A better way to handle array index?


I am looking for a less cryptic way to handle array index.

most cryptic
$array[0]

better
use constant NAME => 0;
$array[NAME]

Any ideas?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: A better way to handle array index?

2002-10-19 Thread Johnstone, Colin
That would be a hash. (or an associative array)

for example I read my form variables into a hash for processing. 

I then reference them by the form fieldname.

#read STDIN, $PostData, $ENV{'CONTENT_LENGTH'};

#print "post data =$PostData";

#postdata will look like this
#[EMAIL PROTECTED]&radAction=unsubscribe&radFormat=html&Submit=Submit
#I need to extract from this string the fields and their values
my @fields = split( /\&/, $PostData);

#Once extracted I write the fieldnames and their values to the formData Hash
#the index is the fieldname from the form
foreach $_ ( @fields ){
  @data = split( /=/, $_ );
  $formData{$data[0]} = $data[1];
}

#This routine is used to check the values in the form data hash for debugging purposes
# while(($k,$v)=each(%formData)){
#   print"$k => $v";
# }


# I access the values of the fields by calling them as below
# another name for a has is an associative array
# print "Email Address =".$formData{'txtEmailAddr'}."";
# print "Action =".$formData{'radAction'}."";
# print "Format =".$formData{'radFormat'}."";

-----Original Message-
From: chris [mailto:chris@;home.com]
Sent: Sunday, October 20, 2002 10:40
To: [EMAIL PROTECTED]
Subject: A better way to handle array index?


I am looking for a less cryptic way to handle array index.

most cryptic
$array[0]

better
use constant NAME => 0;
$array[NAME]

Any ideas?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




A better way to handle array index?

2002-10-19 Thread chris
I am looking for a less cryptic way to handle array index.

most cryptic
$array[0]

better
use constant NAME => 0;
$array[NAME]

Any ideas?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: a better way?

2002-09-26 Thread Jeff 'japhy' Pinyan

On Sep 26, Jerry Preston said:

>I guess it an old 'c' habit.  I do this to check each line for the item I am
>looking for.
>
>I there a better way and why?

  my $found = 0;# have we found 'jeff'?
  while () {  # reads ONE LINE at a time, and stores it in $_
if (/jeff/) {   # if the line has 'jeff' in it
  $found = 1;   # set $found to true
  last; # and stop processing the file
}
  }

is more likely to be more efficient than

  my $found = grep /jeff/, ;

or

  my @lines = ;
  my $found = grep /jeff/, @lines;

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: a better way?

2002-09-26 Thread Nikola Janceski

if you use an array you are using up memory.
small files are okay for that.. but you can do it in the while loop without
the array.

But TIMTOWTDI.

what are you checking for in the lines? Just an example will tell us what's
best for your application.


> -Original Message-
> From: Jerry Preston [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, September 26, 2002 11:51 AM
> To: [EMAIL PROTECTED]
> Cc: Beginners Perl
> Subject: RE: a better way?
> 
> 
> Jeff,
> 
> I guess it an old 'c' habit.  I do this to check each line 
> for the item I am
> looking for.
> 
> I there a better way and why?
> 
> Thanks,
> 
> Jerry
> 
> -Original Message-
> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, September 26, 2002 10:36 AM
> To: Jerry Preston
> Cc: Beginners Perl
> Subject: Re: a better way?
> 
> 
> On Sep 26, Jerry Preston said:
> 
> >Is there a better way?  A Perl way?
> >
> >  $j = 0;
> >  while(  ) {
> >chomp;
> >( $lots[ $j++ ] ) = $_;
> 
> That's usually written as
> 
>  push @lots, $_;
> 
> >  }
> 
> Well, you could do:
> 
>   chomp(@lines = );
> 
> but why do you need the file in an array?
>



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: a better way?

2002-09-26 Thread Jerry Preston

Jeff,

I guess it an old 'c' habit.  I do this to check each line for the item I am
looking for.

I there a better way and why?

Thanks,

Jerry

-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 26, 2002 10:36 AM
To: Jerry Preston
Cc: Beginners Perl
Subject: Re: a better way?


On Sep 26, Jerry Preston said:

>Is there a better way?  A Perl way?
>
>  $j = 0;
>  while(  ) {
>chomp;
>( $lots[ $j++ ] ) = $_;

That's usually written as

 push @lots, $_;

>  }

Well, you could do:

  chomp(@lines = );

but why do you need the file in an array?

--
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: a better way?

2002-09-26 Thread Nikola Janceski

maybe the file has perl code and intends to:

eval{ @lines };

for some wacky reason. I am sure you can remember your early perl days when
you read files into arrays because it was "cool" and easy.


:^P

> -Original Message-
> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, September 26, 2002 11:36 AM
> To: Jerry Preston
> Cc: Beginners Perl
> Subject: Re: a better way?
> 
> 
> but why do you need the file in an array?
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: a better way?

2002-09-26 Thread Jeff 'japhy' Pinyan

On Sep 26, Jerry Preston said:

>Is there a better way?  A Perl way?
>
>  $j = 0;
>  while(  ) {
>chomp;
>( $lots[ $j++ ] ) = $_;

That's usually written as

 push @lots, $_;

>  }

Well, you could do:

  chomp(@lines = );

but why do you need the file in an array?

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: a better way?

2002-09-26 Thread Nikola Janceski

open(FILE, "yourfile") or die "$!";
chomp(my(@lots) = );
close FILE;


> -Original Message-
> From: Jerry Preston [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, September 26, 2002 11:30 AM
> To: Beginners Perl
> Subject: a better way?
> 
> 
> Hi!
> 
> Is there a better way?  A Perl way?
> 
>   $j = 0;
>   while(  ) {
> chomp;
> ( $lots[ $j++ ] ) = $_;
>   }
> 
> ?  @lots = ;
> 
> Thanks,
> 
> Jerry
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




a better way?

2002-09-26 Thread Jerry Preston

Hi!

Is there a better way?  A Perl way?

  $j = 0;
  while(  ) {
chomp;
( $lots[ $j++ ] ) = $_;
  }

?  @lots = ;

Thanks,

Jerry


Re: A better way to list variable names in report format?

2002-09-12 Thread chris

Thank you. Now I can quit the horizontal scrolling.

On Wed, 11 Sep 2002 20:52:59 -0400, [EMAIL PROTECTED] (Bob
Showalter) wrote:
>
>I know beans about formats, but perldoc perlform contains this statement:
>
>"The expressions may be spread out to more than one line if enclosed in
>braces.  If so, the opening brace must be the first token on the first
>line."
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: A better way to list variable names in report format?

2002-09-11 Thread chris

Oops. $$

@$myStuff{qw/column1 column2 column3/};

is definitely an improvement but my list is very long. I think I will
have to assign new variables just to make the listing in multiple
lines. Horizontal scrolling to read off-page code is not nice.

On Wed, 11 Sep 2002 16:42:10 -0700, [EMAIL PROTECTED] (John W. Krahn)
wrote:

>Chris wrote:
>> 
>> I have many report columns and would like the format easier to read.
>> Is there a way to list the variables in multiple lines?
>> 
>> change this
>> 
>> myStuff->{column1},myStuff->{column2},myStuff->{column3}
>
>Do you mean:
>
>$myStuff->{column1}, $myStuff->{column2}, $myStuff->{column3}
>
>> to
>> 
>> myStuff->{column1},
>> myStuff->{column2},
>> myStuff->{column3}
>> 
>> to make the listing more readable but will not compile
>
>How about:
>
>@$myStuff{qw/column1 column2 column3/};
>
>
>
>John


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: A better way for seeding an annoymous hash

2002-08-08 Thread Peter Scott

At 11:44 AM 8/8/02 -0700, drieux wrote:

>On Thursday, August 8, 2002, at 11:04 , Peter Scott wrote:
>
>>At 10:38 AM 8/8/02 -0700, drieux wrote:
>>>I'm not sure the average normal person would feel at home with say:
>>>
>>> %{$by_os{$os_key}}->{$_}++ for(@$found);
>>
>>Especially since it's only by accident that
>>
>> %hash->{key}
>>
>>happens to do the same thing as
>>
>> $hash{key}
>>
>>Many people think it's a bug and plan on eliminating it.
>
>so how do I work around that

Simple; instead of typing

 %hash->{key}

or any more complex variant of it, use

 $hash{key}

>should I use
>
> ${$by_os{$os_key}}{$_}++ for(@$found);
>
>which is only marginally more Dense???

 $by_os{$os_key}{$_}++ for @$found

(Pity that @{$by_os{$os_key}}{@$found}++ doesn't work...)

See perlref.

>we're on the back side of this coding game
>where I clean up all of the sillies that seemed
>useful as I tested them out - and were suppose to
>make the code simpler to read - hence also to maintain...

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Gotta be a better way: File Compares

2001-10-24 Thread Jeff 'japhy' Pinyan

On Oct 24, Kingsbury, Michael said:

>compiling xyz
>"a: warning"
>"b: warning"
>compiling more stuff.
>"a: warning"
>
>I want to get one instance of each warning & output it to a file.  I can do
>that by backticking it through sort, and loading lines that start with a " &
>don't match the previous entry, and then writing that array to a file.
>This seems cumbersome. 

Right.  Use a hash.

  while () {
next unless /^"/;
$error{$_} = 1;
  }

>Part 2.  Given the above, I want to compare an older list of warnings, and
>capture only new ones...Without loading them into arrays & doing
>foreaches on the array to compare, I can't think of how to do this.  

Use another hash.  Let's call it %olderror.

  delete @error{ keys @olderror };

Now the only keys in %error are ones that didn't appear in %olderror.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Gotta be a better way: File Compares

2001-10-24 Thread Kingsbury, Michael

I'm trying to avoid loading this data into arrays & foreaching each one, so
I want to see if anyone has an idea for a better way to do this.

Part 1. 

Given the output from compiling xyz, I end up with a log with warnings as
such


compiling xyz
"a: warning"
"b: warning"
compiling more stuff.
"a: warning"
---  

I want to get one instance of each warning & output it to a file.  I can do
that by backticking it through sort, and loading lines that start with a " &
don't match the previous entry, and then writing that array to a file.
This seems cumbersome. 

Part 2.  Given the above, I want to compare an older list of warnings, and
capture only new ones...Without loading them into arrays & doing
foreaches on the array to compare, I can't think of how to do this.  

Any ideas/suggestions?

-mike


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Is there a better way to do this

2001-09-14 Thread Bradshaw, Brian

Thanks guys, but I wound up using this Tuesday:

while (%result = $finalSet->fetchhash())
{ 
  push @arr_DBanswers, values %result;
}

-Original Message-
From: Curtis Poe [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 14, 2001 4:57 PM
To: MPM; Bradshaw, Brian
Cc: [EMAIL PROTECTED]
Subject: Re: Is there a better way to do this


--- MPM <[EMAIL PROTECTED]> wrote:
> Look into using the map function. It should leave you with the following
> code:
> 
> map {push @arr_DBanswers, $results{$_}} keys %results;
> 
> Scott

Scott,

Actually, it's usually bad to use map in void context as returns a lot data,
merely to throw it
away when you don't use the returned results.  A better answer is:

my @arr_DBanswers = values %results;

Cheers,
Curtis "Ovid" Poe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Is there a better way to do this

2001-09-14 Thread Curtis Poe

--- MPM <[EMAIL PROTECTED]> wrote:
> Look into using the map function. It should leave you with the following
> code:
> 
> map {push @arr_DBanswers, $results{$_}} keys %results;
> 
> Scott

Scott,

Actually, it's usually bad to use map in void context as returns a lot data, merely to 
throw it
away when you don't use the returned results.  A better answer is:

my @arr_DBanswers = values %results;

Cheers,
Curtis "Ovid" Poe

=
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Is there a better way to do this

2001-09-14 Thread Sean Pfister

I think this works:

@arr_DB answers = values(%result);

the array elements won't have any special order however, if that's what you
want.

sean

> -Original Message-
> From: MPM [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 14, 2001 1:39 PM
> To: Bradshaw, Brian
> Cc: [EMAIL PROTECTED]
> Subject: Re: Is there a better way to do this
>
>
> Look into using the map function. It should leave you with the following
> code:
>
> map {push @arr_DBanswers, $results{$_}} keys %results;
>
> Scott
>
>
> On Wed, 12 Sep 2001, Bradshaw, Brian wrote:
> > Another question for the list,
> >   $z = 0;
> >   foreach(@key = keys(%result))
> >   {
> >$arr_DBanswers[$z] = $result{$_};
> >$z=$z+1;
> >   }
> >
> > Is there a better way to break out the values in a hash list to a single
> > array?
> >
> > I'd be curious to know. Thanks.
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Is there a better way to do this

2001-09-14 Thread MPM

Look into using the map function. It should leave you with the following
code:

map {push @arr_DBanswers, $results{$_}} keys %results;

Scott


On Wed, 12 Sep 2001, Bradshaw, Brian wrote:
> Another question for the list,
>   $z = 0;
>   foreach(@key = keys(%result))
>   {
>$arr_DBanswers[$z] = $result{$_};
>$z=$z+1;
>   }
>
> Is there a better way to break out the values in a hash list to a single
> array?
>
> I'd be curious to know. Thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Is there a better way to do this

2001-09-13 Thread Jeff 'japhy/Marillion' Pinyan

On Sep 13, Bradshaw, Brian said:

>while (%result = $finalSet->fetchhash())
>{ 
>  push @arr_DBanswers, values %result;
>}

That code looks fine.  You might want to use 'my' on the %result hash,
since you don't need it existing later.

  while (my %result = $finalSet->fetchhash()) {
push @arr_DBanswers, values %result;
  }

(P.S. where is your McGraw-Hill office?  My dad works on 34th St. in NYC.)

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Is there a better way to do this

2001-09-13 Thread Bradshaw, Brian

That mostly worked. I had to use a while to get the array from the DB
return. 

I wound up with this to get all the values I needed: 

while (%result = $finalSet->fetchhash())
{ 
  push @arr_DBanswers, values %result;
}

Is that good code practice? The the camel book (is it a camel) really
doesn;t help much with the array stuff.

brian

-Original Message-
From: Jason Tiller [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 12, 2001 9:04 PM
To: [EMAIL PROTECTED]
Subject: Re: Is there a better way to do this


Hi, Again, Brian, :)

On Wed, 12 Sep 2001, Bradshaw, Brian wrote:

> I have the code:
>   $z = 0;
>   foreach(@key = keys(%result))
>   {
>$arr_DBanswers[$z] = $result{$_};
>$z=$z+1;
>   }

> Is there a better way to break out the values in a hash list to a
> single array?

How about

@arr_DBanswers = values %result;

?

---Jason

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Is there a better way to do this

2001-09-12 Thread Jason Tiller

Hi, Again, Brian, :)

On Wed, 12 Sep 2001, Bradshaw, Brian wrote:

> I have the code:
>   $z = 0;
>   foreach(@key = keys(%result))
>   {
>$arr_DBanswers[$z] = $result{$_};
>$z=$z+1;
>   }

> Is there a better way to break out the values in a hash list to a
> single array?

How about

@arr_DBanswers = values %result;

?

---Jason


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Is there a better way to do this

2001-09-12 Thread Bradshaw, Brian

Another question for the list,

I have the code:
  $z = 0;
  foreach(@key = keys(%result)) 
  { 
   $arr_DBanswers[$z] = $result{$_};
   $z=$z+1;
  }

Is there a better way to break out the values in a hash list to a single
array?

I'd be curious to know. Thanks.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Re[2]: A better way?

2001-06-26 Thread Stephen Nelson


Actually, calling a subroutine with an ampersand and no parens does not call
the subroutine with no arguments. (To make it clear, though, I AGREE with
Jos I. Boumans' larger point, just correcting a smaller point that I think
makes his point even more clearly...) Using the ampersand without passing
arguments causes a subroutine to be called with the same arguments as its
calling subroutine. So &foo called from bar('a', 'b') does the same thing as
foo('a', 'b').

Say I've got sub foo, which is supposed to just print out a list of things
passed to it, and print an "empty list" message otherwise:

  sub foo {
if (@_) {
  print "Output: ", @_, "\n";
}
else {
  print "Output: empty list\n";
}
  }

Okay, so next I have a subroutine bar(), which calls foo twice:

  sub bar {
 &foo;
 foo();
  }

Then, let's say in the main program I call bar() with arguments:

 bar('a', 'b');

What will the output be? Well, since you're not explicitly passing anything
to foo() in either case, you'd expect it to be:

 Output: empty list
 Output: empty list

BUT IT ISN'T. You get:

 Output: ab
 Output: empty list

I find this a good reason to avoid the & syntax, or to at least always use
parens.

> -Original Message-
> From: Jos I. Boumans [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 23, 2001 2:33 AM
> To: iansmith; [EMAIL PROTECTED]
> Subject: Re: Re[2]: A better way?
>
>
> Ehm, you cant *just* use & and expect all to stay the same...
> concider the following:
>
> if you use a & you dont need to predeclare a sub if you want to
> leave of the
> parenthesis for an argument list:
> ie:
> &foo#calls sub foo with no arguments
> foo   #calls sub foo with no arguments IF you predeclared sub foo
> anywhere... if not, its' a bareword
>
> also, and this is more important, if you set up prototyping for
> your subs, &
> will disable prototype checking...
> now most of the time you dont set up prototypes so it's unlikely you get
> bitten, but the second you change your sub to use prototype's and
> you do not
> leave off the & in your sub calls, they wont get checked
>
> read perldoc perlsub for more information
>
> hope this clears things up,
>
> Jos Boumans
>
> 
>
> > > I am using the most recent from ActiveState, but I tend to stick the &
> > > out there so I can tell at a glance that I am calling a sub.  Does it
> > > cause problems or is it just not needed?
> >
> > It doesn't cause any problems that I am aware of.  Go ahead and use
> > it if it makes subroutines stick out.
>
>




Re: Re[2]: A better way?

2001-06-23 Thread Jos I. Boumans

Ehm, you cant *just* use & and expect all to stay the same...
concider the following:

if you use a & you dont need to predeclare a sub if you want to leave of the
parenthesis for an argument list:
ie:
&foo#calls sub foo with no arguments
foo   #calls sub foo with no arguments IF you predeclared sub foo
anywhere... if not, its' a bareword

also, and this is more important, if you set up prototyping for your subs, &
will disable prototype checking...
now most of the time you dont set up prototypes so it's unlikely you get
bitten, but the second you change your sub to use prototype's and you do not
leave off the & in your sub calls, they wont get checked

read perldoc perlsub for more information

hope this clears things up,

Jos Boumans



> > I am using the most recent from ActiveState, but I tend to stick the &
> > out there so I can tell at a glance that I am calling a sub.  Does it
> > cause problems or is it just not needed?
>
> It doesn't cause any problems that I am aware of.  Go ahead and use
> it if it makes subroutines stick out.




Re[2]: A better way?

2001-06-22 Thread iansmith

On Fri, 22 Jun 2001, Tim Musson wrote:
> I am using the most recent from ActiveState, but I tend to stick the &
> out there so I can tell at a glance that I am calling a sub.  Does it
> cause problems or is it just not needed?

It doesn't cause any problems that I am aware of.  Go ahead and use
it if it makes subroutines stick out.

--
Ian




Re[2]: A better way?

2001-06-22 Thread Tim Musson

Hey Paul,

Friday, June 22, 2001, 10:14:28 PM, you wrote:

>> if ($Var eq "String") {  &Sub($Var1); } elsif ($Var2 =~
>> /$STRING/) { &Sub($Var1); }
>> 
>> Is this a better way?
>> 
>> if (($Var eq "String") || ($Var2 =~ /$STRING/)) {
>> &Sub($Var1);
>> }

P> I like it better.
P> Personally, I'd say

P>   Sub($Var1) if $Var eq "String" or $Var2 =~ /$STRING/;

Ah yes, I have done that before, don't know why I didn't think of it
here...

Thanks!

-- 
[EMAIL PROTECTED]
Using The Bat! eMail v1.53d
Windows NT 5.0.2195 (Service Pack 1)
I was the next door kid's imaginary friend.


NetZero Platinum
No Banner Ads and Unlimited Access
Sign Up Today - Only $9.95 per month!
http://www.netzero.net



Re[2]: A better way?

2001-06-22 Thread Tim Musson

Hey iansmith,

Friday, June 22, 2001, 10:15:49 PM, you wrote:

>> &Sub($Var1); }

snip

i> You can also leave off the & if you are using Perl 5.

I am using the most recent from ActiveState, but I tend to stick the &
out there so I can tell at a glance that I am calling a sub.  Does it
cause problems or is it just not needed?


-- 
[EMAIL PROTECTED]
Using The Bat! eMail v1.53d
Windows NT 5.0.2195 (Service Pack 1)
May I please be excused? My Brain is full. 


NetZero Platinum
No Banner Ads and Unlimited Access
Sign Up Today - Only $9.95 per month!
http://www.netzero.net



Re: A better way?

2001-06-22 Thread iansmith

On Fri, 22 Jun 2001, Tim Musson wrote:
> Is this a better way?
>
> if (($Var eq "String") || ($Var2 =~ /$STRING/)) {
> &Sub($Var1);
> }

I usually write...

if ($Var eq "String" or $Var2 =~ /$STRING/) {

...as I like the diffrent precidence of the 'or' operator.

You can also leave off the & if you are using Perl 5.

As to if it is a better way... I would say yes because it
probably saves a CPU cycle or two, and you reduce the chance
of editing errors by not having duplicate code that can be
a pain to maintain.

--
Ian




Re: A better way?

2001-06-22 Thread Paul


--- Tim Musson <[EMAIL PROTECTED]> wrote:
> Hey all,
> 
> I have this code fragment.
> 
> if ($Var eq "String") { 
> &Sub($Var1);
> } elsif ($Var2 =~ /$STRING/) {
>     &Sub($Var1);
> }
> 
> Is this a better way?
> 
> if (($Var eq "String") || ($Var2 =~ /$STRING/)) {
> &Sub($Var1);
> }

I like it better.
Personally, I'd say

  Sub($Var1) if $Var eq "String" or $Var2 =~ /$STRING/;


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



A better way?

2001-06-22 Thread Tim Musson

Hey all,

I have this code fragment.

if ($Var eq "String") { 
&Sub($Var1);
} elsif ($Var2 =~ /$STRING/) {
&Sub($Var1);
}

Is this a better way?

if (($Var eq "String") || ($Var2 =~ /$STRING/)) {
&Sub($Var1);
}

-- 
[EMAIL PROTECTED]
Using The Bat! eMail v1.53d
Windows NT 5.0.2195 (Service Pack 1)
Why is it called lipstick if you can still move your lips?


NetZero Platinum
No Banner Ads and Unlimited Access
Sign Up Today - Only $9.95 per month!
http://www.netzero.net