Re: Check for empty array

2002-10-04 Thread Dharmender Rai

You can use defined() function by checking for the
first element.
#!/usr/bin perl
use strict;
use warnings;

my @arr=(); ## empty
my $ref=\@arr; ##

if(!defined ($ref->[0]) { 
# do your work here
}

if (!define ($arr->[0]) {
# do your work
}

 --- dan <[EMAIL PROTECTED]> wrote: > or
> 
> if (!$array[0]) {
>  # it's empty
> }
> 
> your choice :)
> 
> dan
> 
> "Nikola Janceski" <[EMAIL PROTECTED]>
> wrote in message
>
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > if(not @array){
> > # it's empty
> > }
> >
> > > -Original Message-
> > > From: Bryan Harris [mailto:[EMAIL PROTECTED]]
> > > Sent: Friday, October 04, 2002 11:58 AM
> > > To: Beginners Perl
> > > Subject: Check for empty array
> > >
> > >
> > >
> > >
> > > What's the easiest way to check whether an array
> is empty?
> > >
> > > I'm really feeling like a beginner today...
> > >
> > > - Bryan
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> [EMAIL PROTECTED]
> > >
> >
> >
>
--
> --
> > 
> > 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]
>  

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

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




Re: package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

Jeff 'japhy' Pinyan wrote:
 > %Foo::Bar::Constants::.  But anyway, here's the trick I'd use:
 >
 >   *short:: = *Foo::Bar::Constants::;
 >   print $short::name;  # $Foo::Bar::Constants::name

ah thanks, this package aliasing thingie is what i had been trying to
accomplish several hours earlier, to no success :-)

-- 
dave



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




Re: package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

Jeff 'japhy' Pinyan wrote:
 > It's important to know that those "constants" aren't as efficient as 
their
 > non-method syntax cousins:
 >
 >   package FOO;
 >   use constant BAR => 10;
 >
 >   package main;
 >   print FOO::BAR;  # at compile-time, Perl makes that 'print 10'
 >   print FOO->BAR;  # FOO->BAR doesn't become 10 until run-time
 >
 > So you're not saving anything.  In fact, I bet THAT is SLOWER than
 > $FOO::BAR.  *AND* it won't interpolate (easily) in strings.  All the more
 > reasons to use real scalars.

well, slower is fine with me, as long as it's FAST ENOUGH for my needs.
i like the way constants look; they stand out compared to variables.

-- 
dave



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




RE: Will not read line and split.

2002-10-04 Thread Jeff 'japhy' Pinyan

On Oct 4, Chuck Belcher said:

>I can now get the first part to open and read a file, however, It still
>does not work when I am reading the directory. The print $file found in
>$in_dir does work it displays a list of files in the directory. The open
>(IN1, "<$file"); does not appear to open the files. I am loosing hair by
>the minute.

You see that $file only holds the NAME (and doesn't need to be chomp()ed),
but you need the PATH and the name.

  open IN1, "< $in_dir/$file" or die "can't read $in_dir/$file: $!";

-- 
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: package name alias (for shorter variable name)

2002-10-04 Thread Jeff 'japhy' Pinyan

On Oct 5, David Garamond said:

>James Edward Gray II wrote:
>> Building on this though, if you made the constants module, couldn't you
>> make them subs?  I believe this is even how the use constant pragma
>> functions.  Heck make it an object oriented module with static methods
>> and it's even designed well.  Just a thought.
>
>good idea. i think i'll use 'use constant' from now on. it's clearer,
>$p->constname works, plus i can get rid of the '$' prefix altogether.
>thanks!

It's important to know that those "constants" aren't as efficient as their
non-method syntax cousins:

  package FOO;
  use constant BAR => 10;

  package main;
  print FOO::BAR;  # at compile-time, Perl makes that 'print 10'
  print FOO->BAR;  # FOO->BAR doesn't become 10 until run-time

So you're not saving anything.  In fact, I bet THAT is SLOWER than
$FOO::BAR.  *AND* it won't interpolate (easily) in strings.  All the more
reasons to use real scalars.

-- 
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: package name alias (for shorter variable name)

2002-10-04 Thread Jeff 'japhy' Pinyan

On Oct 5, David Garamond said:

>indeed. i still want to name my package Foo::Bar::Constants. the 'X' (or
>let's name it 'tmp') is just a temporary prefix to help ease my weary
>typing hands. in python i can do something like this:
>
>  import Foo.Bar.Constants
>  print Foo.Bar.Constants.alice
>  tmp = Foo.Bar.Constants
>  print tmp.alice
>  tmp2 = tmp
>  print tmp2.alice
>
>the three 'print' statements print the same thing. i had thought that in
>perl we can do some aliasing with the symbol table (the * and \*
>stuffs)? this is one beast i have yet to understand.
>
>> Another approach might be to stuff those values into a hash and export just
>> the hash:
>
>hm, i don't think i like this approach. i don't want to hashify everything.

You already HAVE an implicit hash (just like in Python).  It's
%Foo::Bar::Constants::.  But anyway, here's the trick I'd use:

  *short:: = *Foo::Bar::Constants::;
  print $short::name;  # $Foo::Bar::Constants::name

-- 
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: Will not read line and split.

2002-10-04 Thread Chuck Belcher

I added the use strict and use warnings now I get the following...

Global symbol "$file" requires explicit package name at crxml.pl line 8.
Global symbol "$in_dir" requires explicit package name at crxml.pl line
10.
Global symbol "$tstopen" requires explicit package name at crxml.pl line
15.
Global symbol "@fields1" requires explicit package name at crxml.pl line
19.
Execution of crxml.pl aborted due to compilation errors.

Code..

#!/usr/bin/perl
use strict;
use warnings;
# Open Files
opendir(IN_DIR, "/opt/crxml/tstdir") or die "directory does not exist";

# Read Directory
while ($file = readdir(IN_DIR)) {
  next if $file =~ /^\.\.?$/;
  print "$file found in $in_dir\n";
  chomp $file;

#Open Files
  open (FH, "< $file") or die "could not open $file";
  $tstopen = ;
  chomp $tstopen;
  print "$tstopen\n";
  while () {
@fields1 = split /:/, $tstopen;
print "$fields1[0]\n";
print "$fields1[1]\n";
print "$fields1[2]\n";
print "## End of Test Open \n\n";
  }
}

-Original Message-
From: nkuipers [mailto:[EMAIL PROTECTED]] 
Sent: Friday, October 04, 2002 7:49 PM
To: Chuck Belcher
Cc: [EMAIL PROTECTED]
Subject: RE: Will not read line and split.


Put

use strict;
use warnings;

at the top of most programs you ever write.  As for failing calls to
open(), 
phrase the call like this:

open FH, "< $file" or die "Could not read $file: $!";

Once the handle is opened successfully, iterate through the file line by
line 
like this:

while () { ... } #in this block, $_ holds contents of current line

See if cleaning things up a bit like this helps. :)

Regards,

Nathanael


>= Original Message From "Chuck Belcher" <[EMAIL PROTECTED]>

>= I can now get the first part to open and read a file, however, It

>still does not work when I am reading the directory. The print $file 
>found in $in_dir does work it displays a list of files in the 
>directory. The open (IN1, "<$file"); does not appear to open the files.

>I am loosing hair by the minute.
>
>#!/usr/bin/perl
># Input Files
>$in_dir = "/opt/crxml/tstdir";
># Open Files
>opendir(IN_DIR, "$in_dir");
># Read Directory
>while ($file = readdir(IN_DIR)) {
>  next if $file =~ /^\.\.?$/;
>  print "$file found in $in_dir\n";
>  chomp $file;
>#Open Files
>  open (IN1, "< $file");
>  $tstopen = ;
>  chomp $tstopen;
>  print "$tstopen\n";
>@fields1 = split /:/, $tstopen;
>print "$fields1[0]\n";
>
>chuck
>
>-Original Message-
>From: Mark Anderson [mailto:[EMAIL PROTECTED]]
>Sent: Friday, October 04, 2002 7:09 PM
>To: Chuck Belcher
>Subject: RE: Will not read line and split.
>
>
>What errors are you getting?  Are you using strict and warnings?  I 
>would change your open statement in the first example to: open (IN,
>"/opt/crxml/tstdir/updt1.dat") or die "file failed to open $!";
>
>   /\/\ark
>
>-Original Message-
>From: Chuck Belcher [mailto:[EMAIL PROTECTED]]
>Sent: Friday, October 04, 2002 3:59 PM
>To: [EMAIL PROTECTED]
>Subject: Will not read line and split.
>
>
>My goal is to spit a file or files that are in a specific directory.  
>My problem is that I can't read the file.
>
>Attempt to read file:
>#!/usr/bin/perl
>open (IN, " < /opt/crxml/tstdir/updt1.dat");
>until (eof IN) {
>  $line = ;
>  chomp $line;
>  print $line;
>  @fields = split /:/, $line;
>  print "$fields[0]\n";
>}
>
>Same attempt but with directory read
>#!/usr/bin/perl
># Input Files
>$in_dir = "/opt/crxml/tstdir";
># Open Files
>opendir(IN_DIR, "$in_dir");
># Read Directory
>while ($file = readdir(IN_DIR)) {
>  next if $file =~ /^\.\.?$/;
>  print "$file found in $in_dir\n";
>  chomp $file;
>#Open Files
>  open (IN1, "< $file");
>  $tstopen = ;
>  chomp $tstopen;
>  print "$tstopen\n";
>@fields1 = split /:/, $tstopen;
>print "$fields1[0]\n";
>
>Does anyone have any idea what I am doing wrong .. OS is solaris 8.
>
>Chuck
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

"Ain't no blood in my body, it's liquid soul in my veins" ~Roots Manuva


-- 
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: diamond operator

2002-10-04 Thread Todd Wade

John W. Krahn wrote:


>> i run the perlscript with a file suffix like:
>> ./perlscript test1.txt
>> i am trying to reverse the contents of test1.txt line-by-line and print
>> them out. but i dont get any output.any help would be appreciated.
> 
> 
> print reverse <>;
> 

And they say perl is hard!

I once incorrectly replied to a post that wanted to:

> >>  sort arrays by
> >> size.  (The op) need(ed) to sort any number of given arrays, and
> >> operate on the largest to the smallest.

I misunderstood the problem and incorrectly replied with:

> > $ perl -e 'print(sort({$a <=> $b} (7,3,4,9,5,6,1,8,2,)), "\n");'
> > 123456789

but the solution is:

> @x1 = ('a','b','c');
> @x2 = ('d','e');
> @x3 = ('f','g','h','i');
>
> @s = sort {@$b <=> @$a} (\@x1,\@x2,\@x3);
> print "@$_\n" for @s;
> 
> outputs:
> f g h i
> a b c
> d e

My point is that the algorythm is still as simple as sorting an array (once 
you understand references). I guess sorting the arrays would be just as 
easy as it would be in C after your sorting function is written, but try 
printing the reverse of a set of files in a single statement with it.

Todd W.


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




Using modules without root privlidges

2002-10-04 Thread Ramon Hildreth

Hi, I use perl in a restricted environment and I don't have access to
load modules that aren't there. I would like to 
Use additional modules and/or create some of my own.

Is there a workaround for this?

Thanks. 

--www.ramonred.net--




RE: Installing a PM on Linux

2002-10-04 Thread Todd Wade

> 
> Hi all, this is most likely a silly question but in the past I have just
> did installs of Perl modules using the perl -MCPAN -e shell command. How
> do you install a .pm file if you already downloaded from somewhere? Thanks
> in advance as always!
> 
> The standard way to install a downloaded .pm is:
> 
> tar ...
> cd to created subdir
> perl Makefile.PL
> make
> make test
> make install
> 
> See the README after untaring to make sure.

OR you can type:

force install Foo::Bar

at the CPAN prompt and it will reinstall the mod.

*for bundles, this will reinstall the entire bundle!

Todd W

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




RE: Will not read line and split.

2002-10-04 Thread nkuipers

Put

use strict;
use warnings;

at the top of most programs you ever write.  As for failing calls to open(), 
phrase the call like this:

open FH, "< $file" or die "Could not read $file: $!";

Once the handle is opened successfully, iterate through the file line by line 
like this:

while () { ... } #in this block, $_ holds contents of current line

See if cleaning things up a bit like this helps. :)

Regards,

Nathanael


>= Original Message From "Chuck Belcher" <[EMAIL PROTECTED]> =
>I can now get the first part to open and read a file, however, It still
>does not work when I am reading the directory. The print $file found in
>$in_dir does work it displays a list of files in the directory. The open
>(IN1, "<$file"); does not appear to open the files. I am loosing hair by
>the minute.
>
>#!/usr/bin/perl
># Input Files
>$in_dir = "/opt/crxml/tstdir";
># Open Files
>opendir(IN_DIR, "$in_dir");
># Read Directory
>while ($file = readdir(IN_DIR)) {
>  next if $file =~ /^\.\.?$/;
>  print "$file found in $in_dir\n";
>  chomp $file;
>#Open Files
>  open (IN1, "< $file");
>  $tstopen = ;
>  chomp $tstopen;
>  print "$tstopen\n";
>@fields1 = split /:/, $tstopen;
>print "$fields1[0]\n";
>
>chuck
>
>-Original Message-
>From: Mark Anderson [mailto:[EMAIL PROTECTED]]
>Sent: Friday, October 04, 2002 7:09 PM
>To: Chuck Belcher
>Subject: RE: Will not read line and split.
>
>
>What errors are you getting?  Are you using strict and warnings?  I
>would change your open statement in the first example to: open (IN,
>"/opt/crxml/tstdir/updt1.dat") or die "file failed to open $!";
>
>   /\/\ark
>
>-Original Message-
>From: Chuck Belcher [mailto:[EMAIL PROTECTED]]
>Sent: Friday, October 04, 2002 3:59 PM
>To: [EMAIL PROTECTED]
>Subject: Will not read line and split.
>
>
>My goal is to spit a file or files that are in a specific directory.  My
>problem is that I can't read the file.
>
>Attempt to read file:
>#!/usr/bin/perl
>open (IN, " < /opt/crxml/tstdir/updt1.dat");
>until (eof IN) {
>  $line = ;
>  chomp $line;
>  print $line;
>  @fields = split /:/, $line;
>  print "$fields[0]\n";
>}
>
>Same attempt but with directory read
>#!/usr/bin/perl
># Input Files
>$in_dir = "/opt/crxml/tstdir";
># Open Files
>opendir(IN_DIR, "$in_dir");
># Read Directory
>while ($file = readdir(IN_DIR)) {
>  next if $file =~ /^\.\.?$/;
>  print "$file found in $in_dir\n";
>  chomp $file;
>#Open Files
>  open (IN1, "< $file");
>  $tstopen = ;
>  chomp $tstopen;
>  print "$tstopen\n";
>@fields1 = split /:/, $tstopen;
>print "$fields1[0]\n";
>
>Does anyone have any idea what I am doing wrong .. OS is solaris 8.
>
>Chuck
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

"Ain't no blood in my body, it's liquid soul in my veins"
~Roots Manuva


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




RE: Will not read line and split.

2002-10-04 Thread Chuck Belcher

I can now get the first part to open and read a file, however, It still
does not work when I am reading the directory. The print $file found in
$in_dir does work it displays a list of files in the directory. The open
(IN1, "<$file"); does not appear to open the files. I am loosing hair by
the minute.

#!/usr/bin/perl
# Input Files
$in_dir = "/opt/crxml/tstdir";
# Open Files
opendir(IN_DIR, "$in_dir");
# Read Directory
while ($file = readdir(IN_DIR)) {
  next if $file =~ /^\.\.?$/;
  print "$file found in $in_dir\n";
  chomp $file;
#Open Files
  open (IN1, "< $file");
  $tstopen = ;
  chomp $tstopen;
  print "$tstopen\n";
@fields1 = split /:/, $tstopen;
print "$fields1[0]\n";

chuck

-Original Message-
From: Mark Anderson [mailto:[EMAIL PROTECTED]] 
Sent: Friday, October 04, 2002 7:09 PM
To: Chuck Belcher
Subject: RE: Will not read line and split.


What errors are you getting?  Are you using strict and warnings?  I
would change your open statement in the first example to: open (IN,
"/opt/crxml/tstdir/updt1.dat") or die "file failed to open $!";

/\/\ark

-Original Message-
From: Chuck Belcher [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 3:59 PM
To: [EMAIL PROTECTED]
Subject: Will not read line and split.


My goal is to spit a file or files that are in a specific directory.  My
problem is that I can't read the file.

Attempt to read file:
#!/usr/bin/perl
open (IN, " < /opt/crxml/tstdir/updt1.dat");
until (eof IN) {
  $line = ;
  chomp $line;
  print $line;
  @fields = split /:/, $line;
  print "$fields[0]\n";
}

Same attempt but with directory read
#!/usr/bin/perl
# Input Files
$in_dir = "/opt/crxml/tstdir";
# Open Files
opendir(IN_DIR, "$in_dir");
# Read Directory
while ($file = readdir(IN_DIR)) {
  next if $file =~ /^\.\.?$/;
  print "$file found in $in_dir\n";
  chomp $file;
#Open Files
  open (IN1, "< $file");
  $tstopen = ;
  chomp $tstopen;
  print "$tstopen\n";
@fields1 = split /:/, $tstopen;
print "$fields1[0]\n";

Does anyone have any idea what I am doing wrong .. OS is solaris 8.

Chuck


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




Re: WHO IS NAVER-MAILER@naver.com ???

2002-10-04 Thread Michael Kelly

On Thu, Oct 03, 2002 at 01:38:26PM +0800, [EMAIL PROTECTED] wrote:
> Hello, All:
> 
> Every time I send a message to this list, I receive a message from 
> [EMAIL PROTECTED] immediately afterwards. It appears to be garbage 
> (lots of screwy characters...).
> 
> Where is this coming from? Am I the only one receiving these?
> 
> -- 
> Eric P.
> Sunnyvale, CA

Nope! I've gotten the same thing. A visit to http://www.naver.com reveals that
they're probably not garbage characters, but (what appears to me to be) Japanese.

Not sure that's going on here...

*starts watch, waits for another email*
-- 
Michael
San Diego, CA (in the unlikely case that that's relevant)

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




Will not read line and split.

2002-10-04 Thread Chuck Belcher

My goal is to spit a file or files that are in a specific directory.  My
problem is that I can't read the file.

Attempt to read file:
#!/usr/bin/perl
open (IN, " < /opt/crxml/tstdir/updt1.dat");
until (eof IN) {
  $line = ;
  chomp $line;
  print $line;
  @fields = split /:/, $line;
  print "$fields[0]\n";
}

Same attempt but with directory read 
#!/usr/bin/perl
# Input Files
$in_dir = "/opt/crxml/tstdir";
# Open Files
opendir(IN_DIR, "$in_dir");
# Read Directory
while ($file = readdir(IN_DIR)) {
  next if $file =~ /^\.\.?$/;
  print "$file found in $in_dir\n";
  chomp $file;
#Open Files
  open (IN1, "< $file");
  $tstopen = ;
  chomp $tstopen;
  print "$tstopen\n";
@fields1 = split /:/, $tstopen;
print "$fields1[0]\n";

Does anyone have any idea what I am doing wrong .. OS is solaris 8.

Chuck



Re: Sockets and Sleep Question

2002-10-04 Thread Michael Fowler

On Thu, Oct 03, 2002 at 05:12:38PM -0700, Jessee Parker wrote:
> I will definitely take a look at this. How do you determine what your
> current "nice" status is?

nice, with no arguments, will give you your current nice level.  ps and top
will diplay the nice level (or sometimes priority) of processes.  Also,
BSD::Resource, found on CPAN, has a method for retrieving a process's
priority.  I'm fairly certain there are more ways of getting the information.

 
> > How did you verify the condition was never reached?  If you determined it
> > independently of the program printing to its log file then I'd have to see
> > the code to be able to tell you what's going on.
> 
> What I did was had top running and watched the load average.

Ok, the test was seperate.  Have you tried running strace on the program to
see where it's sleeping?  Are you certain it's sleeping, or is it possible
it's blocking on a read or write?


> The code I am using to check the load average is this:
 
> $highload = ".8";
> while (($currload = &Load) > $highload)
> {
> print LOG "Sleeping\n";
> sleep 5;
> }
> 
> sub Load {
> # Test system load and wait if it's too high
> @uptime = split(/,/, `uptime`);
> $fraction = $uptime[3];
> $load = (split /:/, $fraction)[1];
> return $load;
> }

This code doesn't work for me, though it may be because of a difference in
uptime output.  Have you verified Load() returns the value you expect?

Also, &Load has slightly different meaning from Load(), due to the &.  It
doesn't look like it will effect you here, but you should check perldoc
perlsub for the difference between them.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




Re: package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

Bob Showalter wrote:
>use Foo::Bar::Constants ();
>{ package X; Foo::Bar::Constants->import }
>print $X::alice->{name};# prints "Alice"
> 
> Here your using the Exporter functionality, but exporting symbols into the
> "X" namespace instead of your current namespace. The empty parens on the
> "use" prevents the symbol imports into package main. (An alternative is to
> use @EXPORT_OK  in the module and then just pass the @EXPORT_OK list to the
> call to import().)

nice trick :-) but the resulting code seems complex to me. 'use 
constant' is actually what i'm looking for, i think. thanks though.

-- 
dave


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




Re: package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

James Edward Gray II wrote:
> Building on this though, if you made the constants module, couldn't you 
> make them subs?  I believe this is even how the use constant pragma 
> functions.  Heck make it an object oriented module with static methods 
> and it's even designed well.  Just a thought.

good idea. i think i'll use 'use constant' from now on. it's clearer, 
$p->constname works, plus i can get rid of the '$' prefix altogether. 
thanks!

-- 
dave


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




RE: package name alias (for shorter variable name)

2002-10-04 Thread Bob Showalter

> -Original Message-
> From: David Garamond [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 3:17 PM
> To: Bob Showalter
> Cc: [EMAIL PROTECTED]
> Subject: Re: package name alias (for shorter variable name)
> 
> 
> thanks for the answer, bob.
> 
> Bob Showalter wrote:
> > There's nothing that says the file Foo/Bar/Constants.pm 
> must have a "package
> > Foo::Bar::Constants" declaration.
> 
> true, and i've realized that. i come from a python background and by 
> contrast, in python, filename and directory name dictate the 
> package/namespace.

I should have clarified. Those *do* need to match if you're using Exporter.

> 
> > But I think you'll find this kind of thing goes against the 
> spirit of how
> > modules work.
> 
> indeed. i still want to name my package Foo::Bar::Constants. 
> the 'X' (or 
> let's name it 'tmp') is just a temporary prefix to help ease my weary 
> typing hands. in python i can do something like this:
> 
>   import Foo.Bar.Constants
>   print Foo.Bar.Constants.alice
>   tmp = Foo.Bar.Constants
>   print tmp.alice
>   tmp2 = tmp
>   print tmp2.alice
> 
> the three 'print' statements print the same thing. i had 
> thought that in 
> perl we can do some aliasing with the symbol table (the * and \* 
> stuffs)? this is one beast i have yet to understand.

Yes, that's what Exporter does.

> 
> > Another approach might be to stuff those values into a hash 
> and export just
> > the hash:
> 
> hm, i don't think i like this approach. i don't want to 
> hashify everything.

OK, try this:

   Foo/Bar/Constants.pm
   
   package Foo::Bar::Constants;
   
   require Exporter;
   @ISA = qw(Exporter);
   @EXPORT = qw($alice $bruce $charlie $devon);

   $alice = {name=>"Alice", low=>-10, high=>21};
   $bruce = {name=>"Bruce Wayne", low=>-17, high=>5};
   $charlie = {name=>"Charlie", low=>-3, high=>3};
   $devon = {name=>"Devon E.", low=>1, high=>29};

   1;

   main program
   

   use Foo::Bar::Constants ();

   { package X; Foo::Bar::Constants->import }

   print $X::alice->{name};# prints "Alice"

Here your using the Exporter functionality, but exporting symbols into the
"X" namespace instead of your current namespace. The empty parens on the
"use" prevents the symbol imports into package main. (An alternative is to
use @EXPORT_OK  in the module and then just pass the @EXPORT_OK list to the
call to import().)

HTH


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




Re: package name alias (for shorter variable name)

2002-10-04 Thread James Edward Gray II

You're right and I learn something new all the time.

Building on this though, if you made the constants module, couldn't you 
make them subs?  I believe this is even how the use constant pragma 
functions.  Heck make it an object oriented module with static methods 
and it's even designed well.  Just a thought.

James Gray

On Friday, October 4, 2002, at 03:17  PM, David Garamond wrote:

> James Edward Gray II wrote:
>> I haven't tested it, but I'm quite sure:
>> my $p = 'Long::Package::Name';
>> $p->constant;
>> ...works as expected.  If memory serves this is even allowed under 
>> the strict pragma.  If not though, you could always localize a block 
>> with no strict 'refs' where you need it.
>
> $p->foo only works when 'foo' is a subroutine.
>
> btw, i seem to be able to use:
>
>  $tmp = "Foo::Bar::Constants";
>  print ${$tmp."::alice"};
>
> but this fails in 'strict refs'. and though a bit shorter, it's not 
> pretty either (IMO).
>
> -- 
> dave
>


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




Re: package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

James Edward Gray II wrote:
> I haven't tested it, but I'm quite sure:
> 
> my $p = 'Long::Package::Name';
> $p->constant;
> 
> ...works as expected.  If memory serves this is even allowed under the 
> strict pragma.  If not though, you could always localize a block with no 
> strict 'refs' where you need it.

$p->foo only works when 'foo' is a subroutine.

btw, i seem to be able to use:

  $tmp = "Foo::Bar::Constants";
  print ${$tmp."::alice"};

but this fails in 'strict refs'. and though a bit shorter, it's not 
pretty either (IMO).

-- 
dave


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




RE: package name alias (for shorter variable name)

2002-10-04 Thread Timothy Johnson


This could also be a good time to check if your editor supports macros.
Perhaps that would be a solution that would be easier on your hands but
would enable you to keep your package names simple and easy to read/edit.

-Original Message-
From: James Edward Gray II [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 12:51 PM
To: David Garamond
Cc: Timothy Johnson; [EMAIL PROTECTED]
Subject: Re: package name alias (for shorter variable name)


I haven't tested it, but I'm quite sure:

my $p = 'Long::Package::Name';
$p->constant;

works as expected.  If memory serves this is even allowed under the 
strict pragma.  If not though, you could always localize a block with 
no strict 'refs' where you need it.

James Gray

On Friday, October 4, 2002, at 02:31  PM, David Garamond wrote:

> Timothy Johnson wrote:
>> I'm not sure if this is a GOOD idea, but I THINK you can actually get 
>> away
>> with something like this:  In your module, insert a shorter package 
>> name,
>> but keep the module in the same place. So:
>>  package Foo::Bar::Constants;
>>  #do stuff here
>>  package MyConst;
>>  $ConstantA = "My Constant";
>>  #add more constants here
>> Then you can do a 'use Foo::Bar::Constants', and then call the 
>> constants via
>> $MyConst::ConstantA;
>
> but i still want my constants to reside in Foo::Bar::Constants 
> package. it's just that sometimes, when i'm referring to the constants 
> *a lot*, i wish they were referrable with short names. but i prefer 
> not using Exporter and @EXPORT_OK.
>
> -- 
> dave
>
>
> -- 
> 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: package name alias (for shorter variable name)

2002-10-04 Thread James Edward Gray II

I haven't tested it, but I'm quite sure:

my $p = 'Long::Package::Name';
$p->constant;

works as expected.  If memory serves this is even allowed under the 
strict pragma.  If not though, you could always localize a block with 
no strict 'refs' where you need it.

James Gray

On Friday, October 4, 2002, at 02:31  PM, David Garamond wrote:

> Timothy Johnson wrote:
>> I'm not sure if this is a GOOD idea, but I THINK you can actually get 
>> away
>> with something like this:  In your module, insert a shorter package 
>> name,
>> but keep the module in the same place. So:
>>  package Foo::Bar::Constants;
>>  #do stuff here
>>  package MyConst;
>>  $ConstantA = "My Constant";
>>  #add more constants here
>> Then you can do a 'use Foo::Bar::Constants', and then call the 
>> constants via
>> $MyConst::ConstantA;
>
> but i still want my constants to reside in Foo::Bar::Constants 
> package. it's just that sometimes, when i'm referring to the constants 
> *a lot*, i wish they were referrable with short names. but i prefer 
> not using Exporter and @EXPORT_OK.
>
> -- 
> dave
>
>
> -- 
> 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: uptime

2002-10-04 Thread david

Chad Kellerman wrote:

> Hi everyone,
> 
> What would be the easiest way to find the uptime of a linux
> machine?  I don't want to use a system call.  Is there a module I can
> use? Or do I have to open /proc/uptime and calculate it thru there?
> 
> 
> Thanks for the help..
> 
> Chad
> 

yes. try the following:

#!/usr/bin/perl -w
use strict;
use Sys::Load qw/getload uptime/;

print "System load: ", (getload())[0], "\n";
print "System uptime: ", int uptime(), "\n";

__END__

david

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




Re: package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

Timothy Johnson wrote:
> I'm not sure if this is a GOOD idea, but I THINK you can actually get away
> with something like this:  In your module, insert a shorter package name,
> but keep the module in the same place. So:
> 
>   package Foo::Bar::Constants;
> 
>   #do stuff here
> 
>   package MyConst;
>   $ConstantA = "My Constant";
> 
>   #add more constants here
> 
> Then you can do a 'use Foo::Bar::Constants', and then call the constants via
> $MyConst::ConstantA;

but i still want my constants to reside in Foo::Bar::Constants package. 
it's just that sometimes, when i'm referring to the constants *a lot*, i 
wish they were referrable with short names. but i prefer not using 
Exporter and @EXPORT_OK.

-- 
dave


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




Re: package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

thanks for the answer, bob.

Bob Showalter wrote:
> There's nothing that says the file Foo/Bar/Constants.pm must have a "package
> Foo::Bar::Constants" declaration.

true, and i've realized that. i come from a python background and by 
contrast, in python, filename and directory name dictate the 
package/namespace.

> But I think you'll find this kind of thing goes against the spirit of how
> modules work.

indeed. i still want to name my package Foo::Bar::Constants. the 'X' (or 
let's name it 'tmp') is just a temporary prefix to help ease my weary 
typing hands. in python i can do something like this:

  import Foo.Bar.Constants
  print Foo.Bar.Constants.alice
  tmp = Foo.Bar.Constants
  print tmp.alice
  tmp2 = tmp
  print tmp2.alice

the three 'print' statements print the same thing. i had thought that in 
perl we can do some aliasing with the symbol table (the * and \* 
stuffs)? this is one beast i have yet to understand.

> Another approach might be to stuff those values into a hash and export just
> the hash:

hm, i don't think i like this approach. i don't want to hashify everything.

--
dave


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




RE: package name alias (for shorter variable name)

2002-10-04 Thread Bob Showalter

> -Original Message-
> From: David Garamond [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 2:05 PM
> To: [EMAIL PROTECTED]
> Subject: package name alias (for shorter variable name)
> 
> 
> i have several "constants" in a package:
> 
>package Foo::Bar::Constants;
>$alice = {name=>"Alice", low=>-10, high=>21};
>$bruce = {name=>"Bruce Wayne", low=>-17, high=>5};
>$charlie = {name=>"Charlie", low=>-3, high=>3};
>$devon = {name=>"Devon E.", low=>1, high=>29};
> 
> and i want to use them in another package:
> 
>package main;
>require Foo::Bar::Constants;
>use Foo::Bar::Functions;
> 
>add_foo(\@a1, $Foo::Bar::Constants::alice, 1, 3);
>add_foo(\@a1, $Foo::Bar::Constants::bruce, 2, -1);
> 
> is there a way to refer the constants by a shorter package name (say '
> '$X::alice') without having to make the 'Foo::Bar::Constants' an
> Exporter? i also prefer not to import '$alice' and the gang to 'main'
> because there are lots of constants in 'Foo::Bar::Constants' 
> and many of
> them have pretty short and generic names.
> 

Well, you can just do:

Foo/Bar/Constants.pm

   Foo/Bar/Constants.pm
   
   package Foo::Bar::Constants;
   $X::alice = {name=>"Alice", low=>-10, high=>21};
   $X::bruce = {name=>"Bruce Wayne", low=>-17, high=>5};
   $X::charlie = {name=>"Charlie", low=>-3, high=>3};
   $X::devon = {name=>"Devon E.", low=>1, high=>29};

or even

   Foo/Bar/Constants.pm
   
   package X;
   $alice = {name=>"Alice", low=>-10, high=>21};
   $bruce = {name=>"Bruce Wayne", low=>-17, high=>5};
   $charlie = {name=>"Charlie", low=>-3, high=>3};
   $devon = {name=>"Devon E.", low=>1, high=>29};

There's nothing that says the file Foo/Bar/Constants.pm must have a "package
Foo::Bar::Constants" declaration.

But I think you'll find this kind of thing goes against the spirit of how
modules work.

Another approach might be to stuff those values into a hash and export just
the hash:

   Foo/Bar/Constants.pm
   
   package Foo::Bar::Constants;

   use strict;

   require Exporter;
   our @ISA = qw(Exporter);
   our @EXPORT = qw(%C);

   our %C = {
alice => {name=>"Alice", low=>-10, high=>21},
   bruce => {name=>"Bruce Wayne", low=>-17, high=>5},
   charlie => {name=>"Charlie", low=>-3, high=>3},
   devon => {name=>"Devon E.", low=>1, high=>29},
   };

   1;

Now in your main program, just:

   use Foo::Bar::Constants;

   print $C{bruce}{name};   # prints "Bruce Wayne"


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




RE: package name alias (for shorter variable name)

2002-10-04 Thread Timothy Johnson


I'm not sure if this is a GOOD idea, but I THINK you can actually get away
with something like this:  In your module, insert a shorter package name,
but keep the module in the same place. So:

package Foo::Bar::Constants;

#do stuff here

package MyConst;
$ConstantA = "My Constant";

#add more constants here

Then you can do a 'use Foo::Bar::Constants', and then call the constants via
$MyConst::ConstantA;

The only advantage I can see over just making a MyConst.pm is that you can
organize your module files in a way that doesn't conflict with any existing
modules...

-Original Message-
From: David Garamond [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 11:05 AM
To: [EMAIL PROTECTED]
Subject: package name alias (for shorter variable name)


i have several "constants" in a package:

   package Foo::Bar::Constants;
   $alice = {name=>"Alice", low=>-10, high=>21};
   $bruce = {name=>"Bruce Wayne", low=>-17, high=>5};
   $charlie = {name=>"Charlie", low=>-3, high=>3};
   $devon = {name=>"Devon E.", low=>1, high=>29};

and i want to use them in another package:

   package main;
   require Foo::Bar::Constants;
   use Foo::Bar::Functions;

   add_foo(\@a1, $Foo::Bar::Constants::alice, 1, 3);
   add_foo(\@a1, $Foo::Bar::Constants::bruce, 2, -1);

is there a way to refer the constants by a shorter package name (say '
'$X::alice') without having to make the 'Foo::Bar::Constants' an
Exporter? i also prefer not to import '$alice' and the gang to 'main'
because there are lots of constants in 'Foo::Bar::Constants' and many of
them have pretty short and generic names.

thanks in advance.

--
dave



-- 
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]




package name alias (for shorter variable name)

2002-10-04 Thread David Garamond

i have several "constants" in a package:

   package Foo::Bar::Constants;
   $alice = {name=>"Alice", low=>-10, high=>21};
   $bruce = {name=>"Bruce Wayne", low=>-17, high=>5};
   $charlie = {name=>"Charlie", low=>-3, high=>3};
   $devon = {name=>"Devon E.", low=>1, high=>29};

and i want to use them in another package:

   package main;
   require Foo::Bar::Constants;
   use Foo::Bar::Functions;

   add_foo(\@a1, $Foo::Bar::Constants::alice, 1, 3);
   add_foo(\@a1, $Foo::Bar::Constants::bruce, 2, -1);

is there a way to refer the constants by a shorter package name (say '
'$X::alice') without having to make the 'Foo::Bar::Constants' an
Exporter? i also prefer not to import '$alice' and the gang to 'main'
because there are lots of constants in 'Foo::Bar::Constants' and many of
them have pretty short and generic names.

thanks in advance.

--
dave



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




RE: Installing a PM on Linux

2002-10-04 Thread Beau E. Cox

Hi-

The standard way to install a downloaded .pm is:

tar ...
cd to created subdir
perl Makefile.PL
make
make test
make install

See the README after untaring to make sure.

Aloha => Beau.

-Original Message-
From: Jessee Parker [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 6:39 AM
To: [EMAIL PROTECTED]
Subject: Installing a PM on Linux


Hi all, this is most likely a silly question but in the past I have just did
installs of Perl modules using the perl -MCPAN -e shell command. How do you
install a .pm file if you already downloaded from somewhere? Thanks in
advance as always!

Jessee



--
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: drop down box

2002-10-04 Thread Peter Scott

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Imtiaz Ahmad) writes:
>Hi-
>
>Is there a way in PERL to automatically populate second drop down
>based on what is selected in the first drop down.

No.  You need JavaScript.  Because this has to run in the user's browser,
and Perl doesn't.

I'm assuming that (a) You don't want the form to be submitted on each
drop down change so that a (Perl) CGI program can see the selection and
change the form - this would impose a visible delay for the user compared
to JavaScript - and (b) you're talking about an HTML form in a browser,
and not some Tk or other locally run GUI.  It is best to be explicit
about such things when posting so people don't have to make assumptions
to answer you.

>For example 
>If the first drop down has following three choices
>   air
>   land
>   sea
>
>Then if a user is selects land then the second drop should list following
>choices
>   car
>   bus
>   train
[...]

-- 
Peter Scott
http://www.perldebugged.com

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




Re: Check for empty array

2002-10-04 Thread James Edward Gray II

On Friday, October 4, 2002, at 11:21  AM, dan wrote:

> or
>
> if (!$array[0]) {

This tests for a "true" value in the first element of an array, not if  
it's empty.  This test will succeed for the list (undef, 1, 2, "More  
Data"), which is definitely not empty.

>  # it's empty
> }
>
> your choice :)
>
> dan
>
> "Nikola Janceski" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED] 
> ...
>> if(not @array){
>> # it's empty
>> }
>>
>>> -Original Message-
>>> From: Bryan Harris [mailto:[EMAIL PROTECTED]]
>>> Sent: Friday, October 04, 2002 11:58 AM
>>> To: Beginners Perl
>>> Subject: Check for empty array
>>>
>>>
>>>
>>>
>>> What's the easiest way to check whether an array is empty?
>>>
>>> I'm really feeling like a beginner today...
>>>
>>> - Bryan
>>>
>>>
>>> --
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>
>> -- 
>> 
> --
>> 
>> 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]
>


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




Re: Check for empty array

2002-10-04 Thread Jeremy Vinding

On Fri, 2002-10-04 at 10:21, [EMAIL PROTECTED] wrote:
> or
> 
> if (!$array[0]) {
>  # it's empty
> }
> 
> your choice :)
> 
> dan

not quite... try that on this array:
@array = qw(0 1 2 3 4 5 6);

jjv


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




RE: Installing a PM on Linux

2002-10-04 Thread Kipp, James

just open the package up and read the Readme file, it will tell you how to
install it

> -Original Message-
> From: Jessee Parker [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 12:39 PM
> To: [EMAIL PROTECTED]
> Subject: Installing a PM on Linux
> 
> 
> Hi all, this is most likely a silly question but in the past 
> I have just did
> installs of Perl modules using the perl -MCPAN -e shell 
> command. How do you
> install a .pm file if you already downloaded from somewhere? Thanks in
> advance as always!
> 
> Jessee
> 
> 
> 
> -- 
> 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: Check for empty array

2002-10-04 Thread dan

or

if (!$array[0]) {
 # it's empty
}

your choice :)

dan

"Nikola Janceski" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> if(not @array){
> # it's empty
> }
>
> > -Original Message-
> > From: Bryan Harris [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, October 04, 2002 11:58 AM
> > To: Beginners Perl
> > Subject: Check for empty array
> >
> >
> >
> >
> > What's the easiest way to check whether an array is empty?
> >
> > I'm really feeling like a beginner today...
> >
> > - Bryan
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> --
--
> 
> 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]




Installing a PM on Linux

2002-10-04 Thread Jessee Parker

Hi all, this is most likely a silly question but in the past I have just did
installs of Perl modules using the perl -MCPAN -e shell command. How do you
install a .pm file if you already downloaded from somewhere? Thanks in
advance as always!

Jessee



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




RE: Reg Exp

2002-10-04 Thread nkuipers

I also appreciated this solution but for a different reason...it made me look 
up the $- and $+ variables.  Very cool.  I think it would be well worth the 
time for me (and any beginner) to give perldoc perlvar a thorough read...

Cheers everyone,

Nathanael

>= Original Message From "Kipp, James" <[EMAIL PROTECTED]> =
>Thanks. I took a  look at your site and book and found the chapter on look
>ahead. realized how much i was underutilizing them and they could have saved
>me alot of headaches. !!
>
>> -Original Message-
>> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
>> Sent: Friday, October 04, 2002 11:20 AM
>> To: Kipp, James
>> Cc: [EMAIL PROTECTED]
>> Subject: RE: Reg Exp
>>
>>
>> >>   $dna =~ m{
>> >> (?=
>> >>   tag
>> >>   (?:
>> >> .*? tag
>> >> # the substr(...) is there to avoid using $&
>> >> (?{ push @matches, substr($dna, $-[0], $+[0] - $-[0]) })
>> >>   )+
>> >> )
>> >> (?!)
>> >>   }x;
>>
>> First of all, I haven't benchmarked, and I had thought of doing the
>> index() and substr() as approach that J. Krahn demonstrated.
>>
>> The regex uses (?= ... ) to look ahead, so it can match stuff without
>> consuming it.  Here's an example of what I mean:  if I have a string
>> "ABCADEFA", and I want all chunks of "A...A", if the regex actually
>> CONSUMES the "ABCADEFA", then it will have to start after the last A,
>> meaning I've missed embedded "ADEFA" chunk.  By using a
>> look-ahead, I can
>> match text while staying where I am in the string.  Compare:
>>
>>   print "japhy" =~ /(..)/g;
>>
>> with
>>
>>   print "japhy" =~ /(?=(..))/g;
>>
>> Next, to get all the "tag...tag" chunks of varying lengths, I use
>>
>>   /tag(?:.*?tag)+/
>>
>> which matches "tagAtag", "tagAtagBtag", "tagAtagBtagCtag", and so on.
>>
>> The real magic is the code block (?{ ... }) that does the dirty work.
>> First of all, substr($DNA, $-[0], $+[0] - $-[0]) is just a way of
>> accessing $& without incurring the penalties associated with
>> it.  So let's
>> just use $& for now.  The code (push @matches, $&) is
>> executed after every
>> point that the regex has matched up to an occurence of "tag", so in
>>
>>   tagTHIStagTHATtagTHOSEtag
>>
>> it'll happen at:
>>
>>   tagTHIStag X
>>   tagTHIStagTHATtag X
>>   tagTHIStagTHATtagTHOSEtag X
>>  tagTHATtag X
>>  tagTHATtagTHOSEtag X
>> tagTHOSEtag X
>>
>> those six locations.  The last thing in the regex is the
>> (?!), which is a
>> negative look-ahead for nothing, which ALWAYS fails.  This forces the
>> regex to backtrack, so I get all the matches.
>>
>> --
>> 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]

"Ain't no blood in my body, it's liquid soul in my veins"
~Roots Manuva


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




RE: Reg Exp

2002-10-04 Thread Kipp, James

Thanks. I took a  look at your site and book and found the chapter on look
ahead. realized how much i was underutilizing them and they could have saved
me alot of headaches. !!

> -Original Message-
> From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 11:20 AM
> To: Kipp, James
> Cc: [EMAIL PROTECTED]
> Subject: RE: Reg Exp
> 
> 
> >>   $dna =~ m{
> >> (?=
> >>   tag
> >>   (?:
> >> .*? tag
> >> # the substr(...) is there to avoid using $&
> >> (?{ push @matches, substr($dna, $-[0], $+[0] - $-[0]) })
> >>   )+
> >> )
> >> (?!)
> >>   }x;
> 
> First of all, I haven't benchmarked, and I had thought of doing the
> index() and substr() as approach that J. Krahn demonstrated.
> 
> The regex uses (?= ... ) to look ahead, so it can match stuff without
> consuming it.  Here's an example of what I mean:  if I have a string
> "ABCADEFA", and I want all chunks of "A...A", if the regex actually
> CONSUMES the "ABCADEFA", then it will have to start after the last A,
> meaning I've missed embedded "ADEFA" chunk.  By using a 
> look-ahead, I can
> match text while staying where I am in the string.  Compare:
> 
>   print "japhy" =~ /(..)/g;
> 
> with
> 
>   print "japhy" =~ /(?=(..))/g;
> 
> Next, to get all the "tag...tag" chunks of varying lengths, I use
> 
>   /tag(?:.*?tag)+/
> 
> which matches "tagAtag", "tagAtagBtag", "tagAtagBtagCtag", and so on.
> 
> The real magic is the code block (?{ ... }) that does the dirty work.
> First of all, substr($DNA, $-[0], $+[0] - $-[0]) is just a way of
> accessing $& without incurring the penalties associated with 
> it.  So let's
> just use $& for now.  The code (push @matches, $&) is 
> executed after every
> point that the regex has matched up to an occurence of "tag", so in
> 
>   tagTHIStagTHATtagTHOSEtag
> 
> it'll happen at:
> 
>   tagTHIStag X
>   tagTHIStagTHATtag X
>   tagTHIStagTHATtagTHOSEtag X
>  tagTHATtag X
>  tagTHATtagTHOSEtag X
> tagTHOSEtag X
> 
> those six locations.  The last thing in the regex is the 
> (?!), which is a
> negative look-ahead for nothing, which ALWAYS fails.  This forces the
> regex to backtrack, so I get all the matches.
> 
> -- 
> 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: Environment setup

2002-10-04 Thread Kipp, James

several ways:
write a source file with your configs in it, then you can do stuff like
use foo; 
or
require foo; 
and they wil be loaded,  you could write a small module, or use config files
check into the config.pm module, never used it so I am not sure if it is
what your looking for
if you need help with the above methods, let me know

-Original Message-
From: Steve Main [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 11:03 AM
To: Kipp, James; Steve Main; [EMAIL PROTECTED]
Subject: RE: Environment setup




Thanks for the quick reply James, 

How would I set this up in a script and have all the other scripts 
be able to use it? 

-Original Message- 
From: Kipp, James [ mailto:[EMAIL PROTECTED] 
] 
Sent: Friday, October 04, 2002 7:33 AM 
To: 'Steve Main'; [EMAIL PROTECTED] 
Subject: RE: Environment setup 


you can use the %ENV hash 
example: 
$ENV{ORACLE_HOME} = "/opt/oracle/product/9.0.1"; 

> -Original Message- 
> From: Steve Main [ mailto:[EMAIL PROTECTED] 
] 
> Sent: Friday, October 04, 2002 10:23 AM 
> To: [EMAIL PROTECTED] 
> Subject: Environment setup 
> 
> 
> Hello list, 
> 
> I have an Oracle framework written in Korn shell scripts that I am 
> attempting to re-write in Perl.  I am having trouble figuring out 
> how to "source" in environment variables.  For the shell 
> scripts, I have 
> a script that sets all of the global variables and then each script in 
> the framework "sources" that script so that all the scripts 
> start with the same environment.  The gist of what I need is to 
> keep the global variables (like the log directory) in one place 
> and not in each script.  Can anyone tell me how this can 
> be accomplished in Perl? 
> 
> thanks for you time 
> 
> Steve 
> 
> 




Re: Check for empty array

2002-10-04 Thread John W. Krahn

Bryan Harris wrote:
> 
> What's the easiest way to check whether an array is empty?

An array in a scalar context returns the number of elements in the
array.

if ( @array == 0 ) { # explicit test for zero elements

unless ( @array ) { # implicit test for zero elements


John
-- 
use Perl;
program
fulfillment

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




RE: Environment setup

2002-10-04 Thread Steve Main

Ah (light bulb goes on),

I played around with modules yesterday but couldn't get it
to work.. this simple example was all I needed to get
the light bulb to turn on.  

Thanks for your help 

-Original Message-
From: Timothy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 8:29 AM
To: 'Steve Main'; Kipp, James; [EMAIL PROTECTED]
Subject: RE: Environment setup



Another thing you might want to try is making a small module to house your
variables.  You should be able to do something like this:

###
#ora.pm -- houses global variables for Oracle scripts
package Steve::ora;

$server = 'buddha';
$DB = 'mohammed';

1
#don't forget that the last line of the module has to be a 1;

###

Then you can name your file ora.pm and put it in the site/lib/steve
directory and use it like this:

use Steve::ora;

my $server = $Steve::ora::server;
my $DB = $Steve::ora::DB;

-Original Message-
From: Steve Main [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 8:03 AM
To: Kipp, James; Steve Main; [EMAIL PROTECTED]
Subject: RE: Environment setup



Thanks for the quick reply James,

How would I set this up in a script and have all the other scripts
be able to use it?

-Original Message-
From: Kipp, James [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 7:33 AM
To: 'Steve Main'; [EMAIL PROTECTED]
Subject: RE: Environment setup


you can use the %ENV hash
example:
$ENV{ORACLE_HOME} = "/opt/oracle/product/9.0.1";

> -Original Message-
> From: Steve Main [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 10:23 AM
> To: [EMAIL PROTECTED]
> Subject: Environment setup
> 
> 
> Hello list,
> 
> I have an Oracle framework written in Korn shell scripts that I am
> attempting to re-write in Perl.  I am having trouble figuring out
> how to "source" in environment variables.  For the shell 
> scripts, I have
> a script that sets all of the global variables and then each script in
> the framework "sources" that script so that all the scripts
> start with the same environment.  The gist of what I need is to
> keep the global variables (like the log directory) in one place
> and not in each script.  Can anyone tell me how this can
> be accomplished in Perl?
> 
> thanks for you time
> 
> Steve
> 
> 



Re: how can i get rid of these new line characters?

2002-10-04 Thread John W. Krahn

S Wang wrote:
> 
> i have just started writing some scripts in PERL and i am trying to
> catch a deadline, i really wish i could get some help for this problem.
> any suggestion is greatly appreciated.
> 
> i have a set of files with sequences aligned in the following format.
> i wonder how i can eliminate the new line characters within each sequence
> without touching those between sequences?
> 
> .
> 
> 2 chr1 10761 10775 chr19 46520370 46520384 + 941
> acaGGGAACAA
> acagggaaggg
> 
> 3 chr1 10776 11241 chrUn 45411478 45411944 - 12857
> AAGAAGGAAGAAGAGGGTAGAGGAGAAGTGCAGCAAGGGTGGAGGGAGGTGCCCGCGCTGGGTCGGAGGAGCAGGAGTAT
> 
>GGAGGGAAGACTCCTGGGTGGCATGGAGCTCTTGCACCTCTAGGCACTGCCCAGCCCTGTGTCAGCCAGGGCTGAACACAGGATAAGGAACCTGTGTGTGTGACCAACAATCAAAG
> CTACATCTGTGACACAACAGGACACTGCTATGGGCAGTCTCAGTTCTGGCTCGCGTGGACCATCACCATCA
> TCCTGAGCTGCTGCTGTGTCTGCCACCACAGCCAAGCCAGCCCTCAAGTCCAGCAGTAGCAACATGAAATCAA
> CCTGCCTGCCTATCCAGAAGCCCGCAATTACTCAGTGCTACCAATTTCACCAAACTATTTATTACCTT
> CTTATGAGGAAGTGGTGAAC
> AAGAAGGAAGCAGAGGGAAGAAGAAATGAAGGAGGAGGGTGATAGTGCCATGGTGGAGAAACAGGAGGAG
> CACACACTCTACACTGGACACTGTAGTGGACAGTCTCAGTGCTCCAGCTCTGAA
> TTCTGGTATAAGTCCTTGCCTAGGGAGTTATTGGCATCCCAGGGTCTCAGTTACTGCCTCTGCTCCACAGGCAGAGG
> AAAGCATTGTCCAGCCCTCACTCTTAGGGACAATGTTGACTTCTGACTGATGTGGACCATCATCATCT
> TCCGGAGCTGCTGCTGTGTCTGCCACCAATGCTGAGCCCAGGCACTGCCTTCAGACCCAGCAATGACAGCATGAAATCAA
> ATTGATGGCCTACCAGGAAGCCCACAATTACTCATCACTGCCAAGTTCAGGTGCCAAACTATTTATTACCTC
> CTTATGAGGAAGTGATGAAC
> 
> 4 11242 11268 25467376 25467402 - 294
> TAACCTCCACCTGTTTCCCTCCCTGTC
> ATCTTCCAATCCCTTACCCTACC

perl -i~ pe'/^[acgt]+$/i and chomp' yourfile


John
-- 
use Perl;
program
fulfillment

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




drop down box

2002-10-04 Thread Imtiaz ahmad

Hi-

Is there a way in PERL to automatically populate second drop down
based on what is selected in the first drop down.

For example 
If the first drop down has following three choices
air
land
sea

Then if a user is selects land then the second drop should list following
choices
car
bus
train

Then if a user is selects sea then the second drop should list following
choices
boat
submarine


These values will be populated dynamically from a database.

thanks.

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




Re: Check for empty array

2002-10-04 Thread James Edward Gray II

HANDLE_EMPTY() unless @array;

James Gray

On Friday, October 4, 2002, at 10:57  AM, Bryan Harris wrote:

>
>
> What's the easiest way to check whether an array is empty?
>
> I'm really feeling like a beginner today...
>
> - Bryan
>
>
> -- 
> 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: Check for empty array

2002-10-04 Thread Nikola Janceski

if(not @array){
# it's empty
}

> -Original Message-
> From: Bryan Harris [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 11:58 AM
> To: Beginners Perl
> Subject: Check for empty array
> 
> 
> 
> 
> What's the easiest way to check whether an array is empty?
> 
> I'm really feeling like a beginner today...
> 
> - Bryan
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 



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]




Check for empty array

2002-10-04 Thread Bryan Harris



What's the easiest way to check whether an array is empty?

I'm really feeling like a beginner today...

- Bryan


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




RE: how can i get rid of these new line characters?

2002-10-04 Thread Bob Showalter

> -Original Message-
> From: s wang [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 11:00 AM
> To: [EMAIL PROTECTED]
> Subject: how can i get rid of these new line characters?
> 
> 
> 
> i have just started writing some scripts in PERL and i am 
> trying to catch a deadline, i really wish i could get some 
> help for this problem. any suggestion is greatly appreciated.
> 
> i have a set of files with sequences aligned in the following 
> format. i wonder how i can eliminate the new line characters 
> within each sequence without touching those between sequences? 

Here's an attempt at a one-liner that does what I think you want:

perl -000 -i.bak -lpe 's/(?<=\n)(.*?)\n/$1/g' myfile

It reads and writes by "paragraphs".

It then strips the newlines after the first, since it appears you want the
first line of each paragraph to remain a separate line.

> 
> .
> 
> 2 chr1 10761 10775 chr19 46520370 46520384 + 941
> acaGGGAACAA
> acagggaaggg
> 
> 3 chr1 10776 11241 chrUn 45411478 45411944 - 12857
> AAGAAGGAAGAAGAGGGTAGAGGAGAAGTGCAGCAAGGGTGGAGGGAGGTGCCCGCGCTGGG
> TCGGAGGAGCAGGAGTAT
> GGAGGGAAGACTCCTGGGTGGCATGGAGCTCTTGCACCTCTAGGCACTGCCCAGCCCTGTGT
> CAGCCAGGGCTGAACACAGGATAAGGAACCTGTGTGTGTGACCAACAATCAAAG
> CTACATCTGTGACACAACAGGACACTGCTATGGGCAGTCTCAGTTCTGGCTCGCGTGGACCA
> TCACCATCA
> TCCTGAGCTGCTGCTGTGTCTGCCACCACAGCCAAGCCAGCCCTCAAGTCCAGCAGTAGCAA
> CATGAAATCAA
> CCTGCCTGCCTATCCAGAAGCCCGCAATTACTCAGTGCTACCAATTTCACCAAACTAT
> TTATTACCTT
> CTTATGAGGAAGTGGTGAAC
> AAGAAGGAAGCAGAGGGAAGAAGAAATGAAGGAGGAGGGTGATAGTGCCATGGTGGAGAAACAGGAGGAG
> CACACACTCTACACTGGACACTGTAGTGGACAGTCTCAGTGCTCCAGCTCTGAA
> TTCTGGTATAAGTCCTTGCCTAGGGAGTTATTGGCATCCCAGGGTCTCAGTTACTGCCTCTG
> CTCCACAGGCAGAGG
> AAAGCATTGTCCAGCCCTCACTCTTAGGGACAATGTTGACTTCTGACTGATGTG
> GACCATCATCATCT
> TCCGGAGCTGCTGCTGTGTCTGCCACCAATGCTGAGCCCAGGCACTGCCTTCAGACCCAGCA
> ATGACAGCATGAAATCAA
> ATTGATGGCCTACCAGGAAGCCCACAATTACTCATCACTGCCAAGTTCAGGTGC
> CAAACTATTTATTACCTC
> CTTATGAGGAAGTGATGAAC
> 
> 4 11242 11268 25467376 25467402 - 294
> TAACCTCCACCTGTTTCCCTCCCTGTC
> ATCTTCCAATCCCTTACCCTACC

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




Re: how can i get rid of these new line characters?

2002-10-04 Thread James Edward Gray II

Oops, forgot those newlines.  Need to add the 'chomp' below...

On Friday, October 4, 2002, at 10:30  AM, James Edward Gray II wrote:

> With something like the script below.  (I haven't tested it.)  I  
> assumed the blank lines in the sample data really exist.  If they  
> don't, you'll need to change it a bit.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $long_line = '';
> while (<>) {

chomp;

>   if (/^\s*$/) {
>   print "$long_line\n\n";
>   $long_line = '';
>   }
>   else { $long_line .= $_; }
> }
>
> __END__
>
> On Friday, October 4, 2002, at 10:00  AM, s wang wrote:
>
>>
>> i have just started writing some scripts in PERL and i am trying to  
>> catch a deadline, i really wish i could get some help for this  
>> problem. any suggestion is greatly appreciated.
>>
>> i have a set of files with sequences aligned in the following format.  
>> i wonder how i can eliminate the new line characters within each  
>> sequence without touching those between sequences?
>>
>> .
>>
>> 2 chr1 10761 10775 chr19 46520370 46520384 + 941
>> acaGGGAACAA
>> acagggaaggg
>>
>> 3 chr1 10776 11241 chrUn 45411478 45411944 - 12857
>> AAGAAGGAAGAAGAGGGTAGAGGAGAAGTGCAGCAAGGGTGGAGGGAGGTGCCCGCGCTGGGTCGGAGGA 
>> GCAGGAGTAT
>> GGAGGGAAGACTCCTGGGTGGCATGGAGCTCTTGCACCTCTAGGCACTGCCCAGCCCTGTGTCAGCCAGG 
>> GCTGAACACAGGATAAGGAACCTGTGTGTGTGACCAACAATCAAAG
>> CTACATCTGTGACACAACAGGACACTGCTATGGGCAGTCTCAGTTCTGGCTCGCGTGGACCATCACCATC 
>> A
>> TCCTGAGCTGCTGCTGTGTCTGCCACCACAGCCAAGCCAGCCCTCAAGTCCAGCAGTAGCAACATGAAAT 
>> CAA
>> CCTGCCTGCCTATCCAGAAGCCCGCAATTACTCAGTGCTACCAATTTCACCAAACTATTTATTACC 
>> TT
>> CTTATGAGGAAGTGGTGAAC
>> AAGAAGGAAGCAGAGGGAAGAAGAAATGAAGGAGGAGGGTGATAGTGCCATGGTGGAGAAACAGGAGGAG
>> CACACACTCTACACTGGACACTGTAGTGGACAGTCTCAGTGCTCCAGCTCTGAA
>> TTCTGGTATAAGTCCTTGCCTAGGGAGTTATTGGCATCCCAGGGTCTCAGTTACTGCCTCTGCTCCACAG 
>> GCAGAGG
>> AAAGCATTGTCCAGCCCTCACTCTTAGGGACAATGTTGACTTCTGACTGATGTGGACCATCA 
>> TCATCT
>> TCCGGAGCTGCTGCTGTGTCTGCCACCAATGCTGAGCCCAGGCACTGCCTTCAGACCCAGCAATGACAGC 
>> ATGAAATCAA
>> ATTGATGGCCTACCAGGAAGCCCACAATTACTCATCACTGCCAAGTTCAGGTGCCAAACTAT 
>> TTATTACCTC
>> CTTATGAGGAAGTGATGAAC
>>
>> 4 11242 11268 25467376 25467402 - 294
>> TAACCTCCACCTGTTTCCCTCCCTGTC
>> ATCTTCCAATCCCTTACCCTACC
>>
>>
>>
>>
>>
>>
>> -
>> Do you Yahoo!?
>> New DSL Internet Access from SBC & Yahoo!
>


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




Re: how can i get rid of these new line characters?

2002-10-04 Thread James Edward Gray II

With something like the script below.  (I haven't tested it.)  I  
assumed the blank lines in the sample data really exist.  If they  
don't, you'll need to change it a bit.

#!/usr/bin/perl

use strict;
use warnings;

my $long_line = '';
while (<>) {
if (/^\s*$/) {
print "$long_line\n\n";
$long_line = '';
}
else { $long_line .= $_; }
}

__END__

On Friday, October 4, 2002, at 10:00  AM, s wang wrote:

>
> i have just started writing some scripts in PERL and i am trying to  
> catch a deadline, i really wish i could get some help for this  
> problem. any suggestion is greatly appreciated.
>
> i have a set of files with sequences aligned in the following format.  
> i wonder how i can eliminate the new line characters within each  
> sequence without touching those between sequences?
>
> .
>
> 2 chr1 10761 10775 chr19 46520370 46520384 + 941
> acaGGGAACAA
> acagggaaggg
>
> 3 chr1 10776 11241 chrUn 45411478 45411944 - 12857
> AAGAAGGAAGAAGAGGGTAGAGGAGAAGTGCAGCAAGGGTGGAGGGAGGTGCCCGCGCTGGGTCGGAGGAG 
> CAGGAGTAT
> GGAGGGAAGACTCCTGGGTGGCATGGAGCTCTTGCACCTCTAGGCACTGCCCAGCCCTGTGTCAGCCAGGG 
> CTGAACACAGGATAAGGAACCTGTGTGTGTGACCAACAATCAAAG
> CTACATCTGTGACACAACAGGACACTGCTATGGGCAGTCTCAGTTCTGGCTCGCGTGGACCATCACCATCA
> TCCTGAGCTGCTGCTGTGTCTGCCACCACAGCCAAGCCAGCCCTCAAGTCCAGCAGTAGCAACATGAAATC 
> AA
> CCTGCCTGCCTATCCAGAAGCCCGCAATTACTCAGTGCTACCAATTTCACCAAACTATTTATTACCT 
> T
> CTTATGAGGAAGTGGTGAAC
> AAGAAGGAAGCAGAGGGAAGAAGAAATGAAGGAGGAGGGTGATAGTGCCATGGTGGAGAAACAGGAGGAG
> CACACACTCTACACTGGACACTGTAGTGGACAGTCTCAGTGCTCCAGCTCTGAA
> TTCTGGTATAAGTCCTTGCCTAGGGAGTTATTGGCATCCCAGGGTCTCAGTTACTGCCTCTGCTCCACAGG 
> CAGAGG
> AAAGCATTGTCCAGCCCTCACTCTTAGGGACAATGTTGACTTCTGACTGATGTGGACCATCAT 
> CATCT
> TCCGGAGCTGCTGCTGTGTCTGCCACCAATGCTGAGCCCAGGCACTGCCTTCAGACCCAGCAATGACAGCA 
> TGAAATCAA
> ATTGATGGCCTACCAGGAAGCCCACAATTACTCATCACTGCCAAGTTCAGGTGCCAAACTATT 
> TATTACCTC
> CTTATGAGGAAGTGATGAAC
>
> 4 11242 11268 25467376 25467402 - 294
> TAACCTCCACCTGTTTCCCTCCCTGTC
> ATCTTCCAATCCCTTACCCTACC
>
>
>
>
>
>
> -
> Do you Yahoo!?
> New DSL Internet Access from SBC & Yahoo!


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




RE: Environment setup

2002-10-04 Thread Timothy Johnson


Another thing you might want to try is making a small module to house your
variables.  You should be able to do something like this:

###
#ora.pm -- houses global variables for Oracle scripts
package Steve::ora;

$server = 'buddha';
$DB = 'mohammed';

1
#don't forget that the last line of the module has to be a 1;

###

Then you can name your file ora.pm and put it in the site/lib/steve
directory and use it like this:

use Steve::ora;

my $server = $Steve::ora::server;
my $DB = $Steve::ora::DB;

-Original Message-
From: Steve Main [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 8:03 AM
To: Kipp, James; Steve Main; [EMAIL PROTECTED]
Subject: RE: Environment setup



Thanks for the quick reply James,

How would I set this up in a script and have all the other scripts
be able to use it?

-Original Message-
From: Kipp, James [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 7:33 AM
To: 'Steve Main'; [EMAIL PROTECTED]
Subject: RE: Environment setup


you can use the %ENV hash
example:
$ENV{ORACLE_HOME} = "/opt/oracle/product/9.0.1";

> -Original Message-
> From: Steve Main [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 10:23 AM
> To: [EMAIL PROTECTED]
> Subject: Environment setup
> 
> 
> Hello list,
> 
> I have an Oracle framework written in Korn shell scripts that I am
> attempting to re-write in Perl.  I am having trouble figuring out
> how to "source" in environment variables.  For the shell 
> scripts, I have
> a script that sets all of the global variables and then each script in
> the framework "sources" that script so that all the scripts
> start with the same environment.  The gist of what I need is to
> keep the global variables (like the log directory) in one place
> and not in each script.  Can anyone tell me how this can
> be accomplished in Perl?
> 
> thanks for you time
> 
> Steve
> 
> 

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




Re: how can i get rid of these new line characters?

2002-10-04 Thread Jeff 'japhy' Pinyan

On Oct 4, s wang said:

>i have just started writing some scripts in PERL and i am trying to catch
>a deadline, i really wish i could get some help for this problem. any
>suggestion is greatly appreciated.
>
>i have a set of files with sequences aligned in the following format. i
>wonder how i can eliminate the new line characters within each sequence
>without touching those between sequences?

Heh, a much simpler way is:

  open DNA, "< dna.txt" or die "can't read dna.txt: $!";
  open NEW_DNA, "> dna.txt.new" or die "can't write dna.txt.new: $!";

  {
local $/ = "";
while () {
  chomp;  # get rid of the newlines at the end...
  tr/\n//d;  # get rid of the newlines in the text...
  print NEW_DNA "$_\n\n";  # and replace the newlines at the end
}
  }

  close NEW_DNA;
  close DNA;

-- 
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: how can i get rid of these new line characters?

2002-10-04 Thread Jeff 'japhy' Pinyan

On Oct 4, s wang said:

>i have just started writing some scripts in PERL and i am trying to catch
>a deadline, i really wish i could get some help for this problem. any
>suggestion is greatly appreciated.
>
>i have a set of files with sequences aligned in the following format. i
>wonder how i can eliminate the new line characters within each sequence
>without touching those between sequences?

I think the easiest way is to read in a line, then read the next line.  If
the next line is NOT "\n", then remove the last character from the
previous line:

  open DNA, "< dna.txt" or die "can't read dna.txt: $!";
  open NEW_DNA, "> dna.txt.new" or die "can't write dna.txt.new: $!";

  my $prev = ;
  until (eof DNA) {
my $line = ;
if ($line ne "\n") {
chomp $prev if $line ne "\n" and $prev ne "\n";
print NEW_DNA $prev;
$prev = $line;
  }
  print NEW_DNA $prev;

  close NEW_DNA;
  close DNA;

  rename "dna.txt" => "dna.txt.old"
or die "can't rename dna.txt to dna.txt.old: $!";

  rename "dna.txt.new" => "dna.txt"
or die "can't rename dna.txt.new to dna.txt: $!";

-- 
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: how can i get rid of these new line characters?

2002-10-04 Thread nkuipers

A simple, if not elegant, way of doing it assumes that you have each sequence 
in its own variable, say in an array.  Then:

$sequence =~ s/\n//g; #remove ALL newlines
$sequence .= "\n"; #re-add the terminal newline

>= Original Message From "Prachi Shah" <[EMAIL PROTECTED]> =
>Hmmm. One way of doing it could be to read each sequence in the file,
>reading the header and the actual sequence in different variables. And then,
>format the sequence variable to remove all newlines using a regular
>expression. And then write them back to another file.
>
>Hope this helps.
>
>Prachi.
>
>
>Original Message Follows
>From: s wang <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: how can i get rid of these new line characters?
>Date: Fri, 4 Oct 2002 08:00:19 -0700 (PDT)
>
>
>i have just started writing some scripts in PERL and i am trying to catch a
>deadline, i really wish i could get some help for this problem. any
>suggestion is greatly appreciated.
>
>i have a set of files with sequences aligned in the following format. i
>wonder how i can eliminate the new line characters within each sequence
>without touching those between sequences?
>
>.
>
>2 chr1 10761 10775 chr19 46520370 46520384 + 941
>acaGGGAACAA
>acagggaaggg
>
>3 chr1 10776 11241 chrUn 45411478 45411944 - 12857
>AAGAAGGAAGAAGAGGGTAGAGGAGAAGTGCAGCAAGGGTGGAGGGAGGTGCCCGCGCTGGGTCGGAGGAGCAGGAG
TAT
>GGAGGGAAGACTCCTGGGTGGCATGGAGCTCTTGCACCTCTAGGCACTGCCCAGCCCTGTGTCAGCCAGGGCTGAAC
ACAGGATAAGGAACCTGTGTGTGTGACCAACAATCAAAG
>CTACATCTGTGACACAACAGGACACTGCTATGGGCAGTCTCAGTTCTGGCTCGCGTGGACCATCACCATCA
>TCCTGAGCTGCTGCTGTGTCTGCCACCACAGCCAAGCCAGCCCTCAAGTCCAGCAGTAGCAACATGAAATCAA
>CCTGCCTGCCTATCCAGAAGCCCGCAATTACTCAGTGCTACCAATTTCACCAAACTATTTATTACCTT
>CTTATGAGGAAGTGGTGAAC
>AAGAAGGAAGCAGAGGGAAGAAGAAATGAAGGAGGAGGGTGATAGTGCCATGGTGGAGAAACAGGAGGAG
>CACACACTCTACACTGGACACTGTAGTGGACAGTCTCAGTGCTCCAGCTCTGAA
>TTCTGGTATAAGTCCTTGCCTAGGGAGTTATTGGCATCCCAGGGTCTCAGTTACTGCCTCTGCTCCACAGGCAGAGG
>AAAGCATTGTCCAGCCCTCACTCTTAGGGACAATGTTGACTTCTGACTGATGTGGACCATCATCATCT
>TCCGGAGCTGCTGCTGTGTCTGCCACCAATGCTGAGCCCAGGCACTGCCTTCAGACCCAGCAATGACAGCATGAAAT
CAA
>ATTGATGGCCTACCAGGAAGCCCACAATTACTCATCACTGCCAAGTTCAGGTGCCAAACTATTTATTAC
CTC
>CTTATGAGGAAGTGATGAAC
>
>4 11242 11268 25467376 25467402 - 294
>TAACCTCCACCTGTTTCCCTCCCTGTC
>ATCTTCCAATCCCTTACCCTACC
>
>
>
>
>
>
>-
>Do you Yahoo!?
>New DSL Internet Access from SBC & Yahoo!
>
>
>
>
>_
>MSN Photos is the easiest way to share and print your photos:
>http://photos.msn.com/support/worldwide.aspx
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

"Ain't no blood in my body, it's liquid soul in my veins"
~Roots Manuva


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




RE: Reg Exp

2002-10-04 Thread Jeff 'japhy' Pinyan

>>   $dna =~ m{
>> (?=
>>   tag
>>   (?:
>> .*? tag
>> # the substr(...) is there to avoid using $&
>> (?{ push @matches, substr($dna, $-[0], $+[0] - $-[0]) })
>>   )+
>> )
>> (?!)
>>   }x;

First of all, I haven't benchmarked, and I had thought of doing the
index() and substr() as approach that J. Krahn demonstrated.

The regex uses (?= ... ) to look ahead, so it can match stuff without
consuming it.  Here's an example of what I mean:  if I have a string
"ABCADEFA", and I want all chunks of "A...A", if the regex actually
CONSUMES the "ABCADEFA", then it will have to start after the last A,
meaning I've missed embedded "ADEFA" chunk.  By using a look-ahead, I can
match text while staying where I am in the string.  Compare:

  print "japhy" =~ /(..)/g;

with

  print "japhy" =~ /(?=(..))/g;

Next, to get all the "tag...tag" chunks of varying lengths, I use

  /tag(?:.*?tag)+/

which matches "tagAtag", "tagAtagBtag", "tagAtagBtagCtag", and so on.

The real magic is the code block (?{ ... }) that does the dirty work.
First of all, substr($DNA, $-[0], $+[0] - $-[0]) is just a way of
accessing $& without incurring the penalties associated with it.  So let's
just use $& for now.  The code (push @matches, $&) is executed after every
point that the regex has matched up to an occurence of "tag", so in

  tagTHIStagTHATtagTHOSEtag

it'll happen at:

  tagTHIStag X
  tagTHIStagTHATtag X
  tagTHIStagTHATtagTHOSEtag X
 tagTHATtag X
 tagTHATtagTHOSEtag X
tagTHOSEtag X

those six locations.  The last thing in the regex is the (?!), which is a
negative look-ahead for nothing, which ALWAYS fails.  This forces the
regex to backtrack, so I get all the matches.

-- 
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: how can i get rid of these new line characters?

2002-10-04 Thread Prachi Shah

Hmmm. One way of doing it could be to read each sequence in the file, 
reading the header and the actual sequence in different variables. And then, 
format the sequence variable to remove all newlines using a regular 
expression. And then write them back to another file.

Hope this helps.

Prachi.


Original Message Follows
From: s wang <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: how can i get rid of these new line characters?
Date: Fri, 4 Oct 2002 08:00:19 -0700 (PDT)


i have just started writing some scripts in PERL and i am trying to catch a 
deadline, i really wish i could get some help for this problem. any 
suggestion is greatly appreciated.

i have a set of files with sequences aligned in the following format. i 
wonder how i can eliminate the new line characters within each sequence 
without touching those between sequences?

..

2 chr1 10761 10775 chr19 46520370 46520384 + 941
acaGGGAACAA
acagggaaggg

3 chr1 10776 11241 chrUn 45411478 45411944 - 12857
AAGAAGGAAGAAGAGGGTAGAGGAGAAGTGCAGCAAGGGTGGAGGGAGGTGCCCGCGCTGGGTCGGAGGAGCAGGAGTAT
GGAGGGAAGACTCCTGGGTGGCATGGAGCTCTTGCACCTCTAGGCACTGCCCAGCCCTGTGTCAGCCAGGGCTGAACACAGGATAAGGAACCTGTGTGTGTGACCAACAATCAAAG
CTACATCTGTGACACAACAGGACACTGCTATGGGCAGTCTCAGTTCTGGCTCGCGTGGACCATCACCATCA
TCCTGAGCTGCTGCTGTGTCTGCCACCACAGCCAAGCCAGCCCTCAAGTCCAGCAGTAGCAACATGAAATCAA
CCTGCCTGCCTATCCAGAAGCCCGCAATTACTCAGTGCTACCAATTTCACCAAACTATTTATTACCTT
CTTATGAGGAAGTGGTGAAC
AAGAAGGAAGCAGAGGGAAGAAGAAATGAAGGAGGAGGGTGATAGTGCCATGGTGGAGAAACAGGAGGAG
CACACACTCTACACTGGACACTGTAGTGGACAGTCTCAGTGCTCCAGCTCTGAA
TTCTGGTATAAGTCCTTGCCTAGGGAGTTATTGGCATCCCAGGGTCTCAGTTACTGCCTCTGCTCCACAGGCAGAGG
AAAGCATTGTCCAGCCCTCACTCTTAGGGACAATGTTGACTTCTGACTGATGTGGACCATCATCATCT
TCCGGAGCTGCTGCTGTGTCTGCCACCAATGCTGAGCCCAGGCACTGCCTTCAGACCCAGCAATGACAGCATGAAATCAA
ATTGATGGCCTACCAGGAAGCCCACAATTACTCATCACTGCCAAGTTCAGGTGCCAAACTATTTATTACCTC
CTTATGAGGAAGTGATGAAC

4 11242 11268 25467376 25467402 - 294
TAACCTCCACCTGTTTCCCTCCCTGTC
ATCTTCCAATCCCTTACCCTACC






-
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!




_
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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




RE: Environment setup

2002-10-04 Thread Steve Main


Thanks for the quick reply James,

How would I set this up in a script and have all the other scripts
be able to use it?

-Original Message-
From: Kipp, James [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 04, 2002 7:33 AM
To: 'Steve Main'; [EMAIL PROTECTED]
Subject: RE: Environment setup


you can use the %ENV hash
example:
$ENV{ORACLE_HOME} = "/opt/oracle/product/9.0.1";

> -Original Message-
> From: Steve Main [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 10:23 AM
> To: [EMAIL PROTECTED]
> Subject: Environment setup
> 
> 
> Hello list,
> 
> I have an Oracle framework written in Korn shell scripts that I am
> attempting to re-write in Perl.  I am having trouble figuring out
> how to "source" in environment variables.  For the shell 
> scripts, I have
> a script that sets all of the global variables and then each script in
> the framework "sources" that script so that all the scripts
> start with the same environment.  The gist of what I need is to
> keep the global variables (like the log directory) in one place
> and not in each script.  Can anyone tell me how this can
> be accomplished in Perl?
> 
> thanks for you time
> 
> Steve
> 
> 



how can i get rid of these new line characters?

2002-10-04 Thread s wang


i have just started writing some scripts in PERL and i am trying to catch a deadline, 
i really wish i could get some help for this problem. any suggestion is greatly 
appreciated.

i have a set of files with sequences aligned in the following format. i wonder how i 
can eliminate the new line characters within each sequence without touching those 
between sequences? 

.

2 chr1 10761 10775 chr19 46520370 46520384 + 941
acaGGGAACAA
acagggaaggg

3 chr1 10776 11241 chrUn 45411478 45411944 - 12857
AAGAAGGAAGAAGAGGGTAGAGGAGAAGTGCAGCAAGGGTGGAGGGAGGTGCCCGCGCTGGGTCGGAGGAGCAGGAGTAT
GGAGGGAAGACTCCTGGGTGGCATGGAGCTCTTGCACCTCTAGGCACTGCCCAGCCCTGTGTCAGCCAGGGCTGAACACAGGATAAGGAACCTGTGTGTGTGACCAACAATCAAAG
CTACATCTGTGACACAACAGGACACTGCTATGGGCAGTCTCAGTTCTGGCTCGCGTGGACCATCACCATCA
TCCTGAGCTGCTGCTGTGTCTGCCACCACAGCCAAGCCAGCCCTCAAGTCCAGCAGTAGCAACATGAAATCAA
CCTGCCTGCCTATCCAGAAGCCCGCAATTACTCAGTGCTACCAATTTCACCAAACTATTTATTACCTT
CTTATGAGGAAGTGGTGAAC
AAGAAGGAAGCAGAGGGAAGAAGAAATGAAGGAGGAGGGTGATAGTGCCATGGTGGAGAAACAGGAGGAG
CACACACTCTACACTGGACACTGTAGTGGACAGTCTCAGTGCTCCAGCTCTGAA
TTCTGGTATAAGTCCTTGCCTAGGGAGTTATTGGCATCCCAGGGTCTCAGTTACTGCCTCTGCTCCACAGGCAGAGG
AAAGCATTGTCCAGCCCTCACTCTTAGGGACAATGTTGACTTCTGACTGATGTGGACCATCATCATCT
TCCGGAGCTGCTGCTGTGTCTGCCACCAATGCTGAGCCCAGGCACTGCCTTCAGACCCAGCAATGACAGCATGAAATCAA
ATTGATGGCCTACCAGGAAGCCCACAATTACTCATCACTGCCAAGTTCAGGTGCCAAACTATTTATTACCTC
CTTATGAGGAAGTGATGAAC

4 11242 11268 25467376 25467402 - 294
TAACCTCCACCTGTTTCCCTCCCTGTC
ATCTTCCAATCCCTTACCCTACC


 



-
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!


Re: handling large data files

2002-10-04 Thread James Edward Gray II

On Friday, October 4, 2002, at 09:21  AM, Jerry Preston wrote:

> Hi!,

Howdy.

> I am look for a better way and a faster way to deal with a 4 - 8 meg  
> data
> file.   This file has been saved as an .cvs file for excel to read in.

A "better" way, is pretty open to interpretation, so here's my  
interpretation.

> All I am interested in is the first  three cells of ',' delimited data.
>
> Die,Row 0, Column 11
> Test Result,1
>  Score,1
>  PMark Score,0
> k Score,0
> Score,0
>
> Defects,0
>
> Mark Measurements,276
> Measurement
> 0,0,8.030399,740.998413,21.542923,16.721996,817.562500,22.048611,881.06 
> 2500,
> 29.847174,11.604215,17.210899,685.522644,16.721996,0,0
> Measurement
> 1,1,12.346605,804.399353,25.516476,8.607447,817.562500,8.607447,881.062 
> 500,2
> 6.055706,28.836847,20.028336,748.923584,9.931009,0,0
>
>   open( FI, $file_path )   || die "unable to open $file_path $!\n";
>   @file_data = ;
>   close FI;

That array assignment above "slups" the entire file into memory.  Let's  
not do that.  Remove it and the close line.

>   LINE: foreach $_ ( @file_data ) {

Then we can make a simple change right here:

LINE:  while (< FI>) {

This line reads one line and assigns it to $_, but we process each line  
as it comes in now instead of slurping huge files into memory.  Much  
better.

> if( /^Die,Row/ ) {
>   ($row, $col) = /(\d+)/g;
> }

Better would be:

if (/^Die,Row (\d+), Column (\d+)/) {
($row, $col) = ($1, $2);
}

> if( /^PMark Measurements/ ) {
>   ($cnt) = /(\d+)/g;

The if should probably be an elsif here, so it's only checked if the  
first if failed.  In other words, its a Die,Row line or a Mark  
Measurements line, not both.

I believe you also have a rogue P in that pattern.

And again, better is:

elsif (/^Mark Measurements,(\d+)/) {
$cnt = $1;
}

Below this your code gets pretty confusing.  Here are some thoughts:

* use strict; at the top of the program.  This forces you to declare  
your variables before you use them, making your code easier for us the  
read and thus help you with.  Always, always, ALWAYS do this!

* Why are we checking the line type again below?  Let's do everything  
we need to do with a line before we move on.  (The /^Measurement/ check  
below should be /^Mark Measurement/ too, I think.)

* Yikes, while () {, are we reading from a file handle we closed?   
Let's not do that.  Try to rethink your logic (or explain it to us and  
let us help you rethink it) too handle one line at a time.  That's a  
pretty good general rule for parsing.

* Do you realize that

@fields = split /,/, $_;

Fills the fields array with all the values on a line that you could  
then walk through?  WARNING:  This only works if commas do not appear  
in the fields, but that looks true in your example data.

Clean it up a bit.  Help us read it and send it back to us if you're  
still having problems.

James Gray

>   if( $cnt > $max ) {
> $max = $cnt;
>   }
>   if( $cnt > 0 ) {
> $row_col[ $jp++ ] = "$row,$col";
> while(  ) {
>   if( /^Die,Row/ ) {
> ($row, $col) = /(\d+)/g;
> $row_col[ $jp++ ] = "$row,$col";
> next LINE;
>   }
>   $Z=0;
>   if( /^Measurement/ ) {
> (@data) = split( /\,/ );
> if( $data[ 2 ] > 0 ) {
>   ($meas) = ($data[0]) =~ /(\d+)/g;
>   $data{ "$row,$col" }{ $meas } = $data[2];
>   $data{ "$row,$col" }{ $meas }{ $data[1] } = $data[2];
> }
>   }
> }
>   }
> }
>   }
> @file_data = ();
>
>


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




Re: handling large data files

2002-10-04 Thread John W. Krahn

Jerry Preston wrote:
> 
> Hi!,

Hello,

> I am look for a better way and a faster way to deal with a 4 - 8 meg data
> file.   This file has been saved as an .cvs file for excel to read in.
> 
> [snip]
> 
>   open( FI, $file_path )   || die "unable to open $file_path $!\n";
>   @file_data = ;
>   close FI;
> 
>   LINE: foreach $_ ( @file_data ) {

Reading the entire file into an array is going to be very slow.  Loop
through the file one line at a time.

open( FI, $file_path )   || die "unable to open $file_path $!\n";

LINE: while (  ) {



John
-- 
use Perl;
program
fulfillment

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




RE: Reg Exp

2002-10-04 Thread Kipp, James

>
> Here is my solution:
> 
>   my $dna = ...;
>   my @matches;
> 
>   $dna =~ m{
> (?=
>   tag
>   (?:
> .*? tag
> # the substr(...) is there to avoid using $&
> (?{ push @matches, substr($dna, $-[0], $+[0] - $-[0]) })
>   )+
> )
> (?!)
>   }x;
> 
> Now @matches holds all those tag...tag strings.  I'll explain 
> the regex if
> people would like. ;)

YES PLEASE !



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




RE: Environment setup

2002-10-04 Thread Kipp, James

you can use the %ENV hash
example:
$ENV{ORACLE_HOME} = "/opt/oracle/product/9.0.1";

> -Original Message-
> From: Steve Main [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 10:23 AM
> To: [EMAIL PROTECTED]
> Subject: Environment setup
> 
> 
> Hello list,
> 
> I have an Oracle framework written in Korn shell scripts that I am
> attempting to re-write in Perl.  I am having trouble figuring out
> how to "source" in environment variables.  For the shell 
> scripts, I have
> a script that sets all of the global variables and then each script in
> the framework "sources" that script so that all the scripts
> start with the same environment.  The gist of what I need is to
> keep the global variables (like the log directory) in one place
> and not in each script.  Can anyone tell me how this can
> be accomplished in Perl?
> 
> thanks for you time
> 
> Steve
> 
> 


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




Re: Reg Exp

2002-10-04 Thread John W. Krahn

Cedric wrote:
> 
> First of all, sorry for my poor english.
> I work with DNA sequence and want to extract relevant motives of course
> using regular expression.
> A concrete example will be better than a long description of my problem, so:
> 
> Here is a string corresponding to my DNA strand :
> 
> cgttgctagctgctatcgatgtgctagtcgatgctagtgcatgcgtagtgcagtcatatgctaggcat
> 
> I want to extract all the substrings beginning with tag and finishing with
> tag including substrings with same start point but different length like :
> 
> tagctgctatcgatgtgctag
> tagctgctatcgatgtgctagtcgatgctag
> tagctgctatcgatgtgctagtcgatgctagtgcatgcgtag
> 
> How to write a regular expression which will not increase the value pos()
> after finding one match but keep the same value of pos() and extract all
> sequences with different lengths ?
> 
> To sum up, if I have this sequence :
> 
> taggcgttatcgctagcgcatcgataggctactattcgtagcc
> 
> My regular expression must extract :
> 
> taggcgttatcgctag
> taggcgttatcgctagcgcatcgatag
> taggcgttatcgctagcgcatcgataggctactattcgtag
>  tagcgcatcgatag
>  tagcgcatcgataggctactattcgtag
> taggctactattcgtag
> 
> Thanks for any help ...


Here is a way to do it without using regular expressions:

$ perl -le'
$DNA =
"cgttgctagctgctatcgatgtgctagtcgatgctagtgcatgcgtagtgcagtcatatgctaggcat";

$i = -1;
push @tags, $i while ( $i = index $DNA, "tag", $i + 1 ) >= 0;

die "tag not found\n" if @tags < 2;

for $x ( 0 .. $#tags - 1 ) {
for $y ( $x + 1 .. $#tags ) {
print substr( $DNA, $tags[$x], $tags[$y] - $tags[$x] ), "tag";
}
}
'
tagctgctatcgatgtgctag
tagctgctatcgatgtgctagtcgatgctag
tagctgctatcgatgtgctagtcgatgctagtgcatgcgtag
tagctgctatcgatgtgctagtcgatgctagtgcatgcgtagtgcagtcatatgctag
tagtcgatgctag
tagtcgatgctagtgcatgcgtag
tagtcgatgctagtgcatgcgtagtgcagtcatatgctag
tagtgcatgcgtag
tagtgcatgcgtagtgcagtcatatgctag
tagtgcagtcatatgctag



John
-- 
use Perl;
program
fulfillment

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




Environment setup

2002-10-04 Thread Steve Main

Hello list,

I have an Oracle framework written in Korn shell scripts that I am
attempting to re-write in Perl.  I am having trouble figuring out
how to "source" in environment variables.  For the shell scripts, I have
a script that sets all of the global variables and then each script in
the framework "sources" that script so that all the scripts
start with the same environment.  The gist of what I need is to
keep the global variables (like the log directory) in one place
and not in each script.  Can anyone tell me how this can
be accomplished in Perl?

thanks for you time

Steve




handling large data files

2002-10-04 Thread Jerry Preston

Hi!,

I am look for a better way and a faster way to deal with a 4 - 8 meg data
file.   This file has been saved as an .cvs file for excel to read in.

All I am interested in is the first  three cells of ',' delimited data.

Die,Row 0, Column 11
Test Result,1
 Score,1
 PMark Score,0
k Score,0
Score,0

Defects,0

Mark Measurements,276
Measurement
0,0,8.030399,740.998413,21.542923,16.721996,817.562500,22.048611,881.062500,
29.847174,11.604215,17.210899,685.522644,16.721996,0,0
Measurement
1,1,12.346605,804.399353,25.516476,8.607447,817.562500,8.607447,881.062500,2
6.055706,28.836847,20.028336,748.923584,9.931009,0,0

  open( FI, $file_path )   || die "unable to open $file_path $!\n";
  @file_data = ;
  close FI;

  LINE: foreach $_ ( @file_data ) {
if( /^Die,Row/ ) {
  ($row, $col) = /(\d+)/g;
}
if( /^PMark Measurements/ ) {
  ($cnt) = /(\d+)/g;
  if( $cnt > $max ) {
$max = $cnt;
  }
  if( $cnt > 0 ) {
$row_col[ $jp++ ] = "$row,$col";
while(  ) {
  if( /^Die,Row/ ) {
($row, $col) = /(\d+)/g;
$row_col[ $jp++ ] = "$row,$col";
next LINE;
  }
  $Z=0;
  if( /^Measurement/ ) {
(@data) = split( /\,/ );
if( $data[ 2 ] > 0 ) {
  ($meas) = ($data[0]) =~ /(\d+)/g;
  $data{ "$row,$col" }{ $meas } = $data[2];
  $data{ "$row,$col" }{ $meas }{ $data[1] } = $data[2];
}
  }
}
  }
}
  }
@file_data = ();





Re: Regular expression

2002-10-04 Thread Bruno Negrao - Perl List

> Hi Javeed ,
>
> the last element of the array is $attt[$#attt]. If you have one line per
> element, that should do it.
Right. This is the easiest way. But, just to answer him, what he could do
using regular expression could be something like:
foreach (@attt) {
/=/ && ( ($out) = (split (/=/))[1] );
}

Bruno.


>
> R
>
> At 14:24 04/10/2002 +0530, Javeed SAR wrote:
>
> >I have the following output in array @attt
> >I want the last line in a variable $out.
> >What should the regular expression be?
> >
> >
> >attribute type "SYNC_CHECK"
> >   created 04-Oct-02.09:36:42 by javeed.clearuser@BLRK35ED
> >   "for testing"
> >   owner: HIS\javeed
> >   group: HIS\clearuser
> >   scope: this VOB (ordinary type)
> >   value type: string
> >   Attributes:
> > SYNC_CHECK = "HELLO"
> >
> >
> >Regards
> >j
>
>
> --
> 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: Reg Exp

2002-10-04 Thread Jeff 'japhy' Pinyan

On Oct 4, Cedric said:

>cgttgctagctgctatcgatgtgctagtcgatgctagtgcatgcgtagtgcagtcatatgctaggcat
>
>I want to extract all the substrings beginning with tag and finishing with
>tag including substrings with same start point but different length like :
>
>tagctgctatcgatgtgctag
>tagctgctatcgatgtgctagtcgatgctag
>tagctgctatcgatgtgctagtcgatgctagtgcatgcgtag

One way of matching your sequences would be to use a regex with code
blocks embedded in it.

Here is my solution:

  my $dna = ...;
  my @matches;

  $dna =~ m{
(?=
  tag
  (?:
.*? tag
# the substr(...) is there to avoid using $&
(?{ push @matches, substr($dna, $-[0], $+[0] - $-[0]) })
  )+
)
(?!)
  }x;

Now @matches holds all those tag...tag strings.  I'll explain the regex if
people would like. ;)

-- 
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: uptime

2002-10-04 Thread zentara

On 03 Oct 2002 09:25:03 -0400, [EMAIL PROTECTED] (Chad Kellerman)
wrote:

>Hi everyone,
>
>What would be the easiest way to find the uptime of a linux
>machine?  I don't want to use a system call.  Is there a module I can
>use? Or do I have to open /proc/uptime and calculate it thru there?

Here's a uptime script which runs nice:
#3
#!/usr/bin/perl -w
use strict;
open UPTIME, "/proc/uptime" or die "cannot open '/proc/uptime'.\n";

my $time = ;
close UPTIME;
$time = sprintf "%.0f", $time =~ /^(\d+)\./;
print time2string($time), "\n";

#
sub time2string {
my $time = shift;
return if ! defined $time or $time !~ /^\-?\d+$/;
my $prefix;
if ($time < 0) {
$time = - $time;
$prefix = "- ";
}else {$prefix='';}
my $s = $time % 60;
my $m = ($time / 60) % 60;
my $h = ($time / (60 * 60)) % 24;
my $d = int($time / (24 * 60 * 60));

(my $y, $d)  = modulus_thingamajig(365, $d);
(my $mo, $d) = modulus_thingamajig(30, $d);
(my $w, $d)  = modulus_thingamajig(7, $d);

my @data;
push @data, sprintf "%dy", $y if $y != 0;
push @data, sprintf "%dmo", $mo if $mo != 0;
push @data, sprintf "%dw", $w if $w != 0;
push @data, sprintf "%dd", $d if $d != 0;
push @data, sprintf "%dh", $h if $h != 0;
push @data, sprintf "%dm", $m if $m != 0;
push @data, sprintf "%ds", $s if $s != 0 or ! @data;

return $prefix . join ' ', @data;
}

sub modulus_thingamajig {
my ($days, $d) = @_;
my $return;
if ($d >= $days) {
$return = int($d / $days);
$d = $d % $days;
} else {
$return = 0;
}
return ($return, $d);
}
##






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




Re: remove duplicate lines

2002-10-04 Thread Sudarshan Raghavan

On Fri, 4 Oct 2002, waytech wrote:

> hi everyone,
> 
> Thanks for all replys about my question.
> 
>  I know here are lots of  perl experts.
> 
>  it's amazing that someone can short
> 
> that long program into one line.
> 
> I am a  perl newbie, i wonder
> 
> whether someone can  explain  what
> 
> these guys wrote(like what
> 
> Sudarshan Raghavan wrote
> 
> ). I really can not understand.
> 
> Since this group called " perl beginners",
> 
> i hope i can get some explanations.
> 
> Tanks a lot.
> 
>  kevin

I will explain the one-liners in the order in which they were posted

1) perl -e'while(<>){print unless $seen{$_}++}' outfile

-e command line switch: Type perldoc perlrun and read about the -e option.

<> (diamond operator): perldoc perlop, search for 'The null filehandle'

print unless $seen{$_}++ is the same as
unless ($seen{$_}++) {
print;
}

2) perl -n -e 'print unless $seen{$_}++' infile >outfile

Removed the while (<>) {} wrapper from the first one. The -n command line 
switch will do this for us.
perldoc perlrun # -n switch

3) perl -ne'$s{$_}++||print' infile >outfile

Same as 2, $s{$_}++||print works like this, the print statement is 
executed only if $s{$_}++ evaluates to false (lazy evaluation).
It is the same as

while (<>) {
  unless ($s{$_}++) {
print;
  }
}

4) perl -pe'$+{$_}++&&y+++cd' infile >outfile

# perldoc perlrun for the -p switch

%+ is the hash used here instead of %s or %seen used in the above examples.
If $+{$_}++ evaluates to true then execute y+++cd (lazy evaluation again)
y+++cd is nothing but y///cd or tr///cd, using '+' as a delimiter instead 
of '/'
 
The above one-liner can be written as
while (<>) {
  if ($+{$_}++) {
tr///cd;
  }
  print;
}

For y/// or tr///: perldoc perlop # Search for Quote-like Operators 

5) perl -pe'$s{$_}++&&s{.+}$$s' infile >outfile
Borken down to

while (<>) {
  if ($s{$_}++) {
s{.+}$$s; # same s/.+//s;
  }
}

/s modifier makes '.' match on a newline too (by default it does not)
perldoc perlre

When matching delimiters like '{' and '}' are used to enclose the left 
hand side of s/// or tr///, you can use another pair or character to 
enclose the right hand side. In this case the character '$' is used to 
enclose the RHS.

6) perl -pe'$s{$_}++&&s{$_}++' infile >outfile

Same as above, using '+ to enclose the RHS instead of '$'. Note this will 
not work if any regex metacharacters are a part of $_ (the line read in).
You can overcome this by using \Q and \E. perldoc perlre




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




Reg Exp

2002-10-04 Thread Cedric

First of all, sorry for my poor english.
I work with DNA sequence and want to extract relevant motives of course
using regular expression.
A concrete example will be better than a long description of my problem, so
:

Here is a string corresponding to my DNA strand :

cgttgctagctgctatcgatgtgctagtcgatgctagtgcatgcgtagtgcagtcatatgctaggcat

I want to extract all the substrings beginning with tag and finishing with
tag including substrings with same start point but different length like :

tagctgctatcgatgtgctag
tagctgctatcgatgtgctagtcgatgctag
tagctgctatcgatgtgctagtcgatgctagtgcatgcgtag

How to write a regular expression which will not increase the value pos()
after finding one match but keep the same value of pos() and extract all
sequences with different lengths ?

To sum up, if I have this sequence :

taggcgttatcgctagcgcatcgataggctactattcgtagcc

My regular expression must extract :

taggcgttatcgctag
taggcgttatcgctagcgcatcgatag
taggcgttatcgctagcgcatcgataggctactattcgtag
tagcgcatcgatag
tagcgcatcgataggctactattcgtag
  taggctactattcgtag

Thanks for any help ...



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




Re: remove duplicate lines

2002-10-04 Thread waytech

hi everyone,

Thanks for all replys about my question.

 I know here are lots of  perl experts.

 it's amazing that someone can short

that long program into one line.

I am a  perl newbie, i wonder

whether someone can  explain  what

these guys wrote(like what

Sudarshan Raghavan wrote

). I really can not understand.

Since this group called " perl beginners",

i hope i can get some explanations.

Tanks a lot.

 kevin

jontn_swift wrote:

>This is a classic case for my favorite one-liner:
>
>perl -e'while(<>){print unless $seen{$_}++}' outfile
>
>
>
> 
>
>On Wed, 02 Oct 2002 04:17:29 -0400, Sudarshan Raghavan wrote:
>
>  
>
>>On Fri, 27 Sep 2002, waytech wrote:
>>
>>
>>
>>>hi,
>>>
>>>i want to remove duplicate lines from one file(original file), and save
>>>the result to another file.
>>>
>>>the origianl file like this:
>>>
>>>
>>>[EMAIL PROTECTED]
>>>[EMAIL PROTECTED]
>>>[EMAIL PROTECTED]
>>>[EMAIL PROTECTED]
>>>[EMAIL PROTECTED]
>>>[EMAIL PROTECTED]
>>>---
>>>
>>>with each email address a line. I want to remove the duplicate
>>>lines(emais adresses) and
>>>
>>>save the result to a new file.
>>>
>>>I wrote a program , but it output nothing. can someome help ?
>>>
>>>Thanks a lot.
>>>
>>>  kevin
>>>
>>>---
>>>#!/usr/bin/perl -w
>>>###
>>>#Remove the duplicate line   #
>>>#from a orginal file and save #
>>>#the result to a file. #
>>>###
>>>print "Enter the file that has duplicate lines.\n";
>>>$Dupli_file=;
>>>chomp;
>>>  
>>>
>>chomp by default works on $_, to chomp $Dupli_file you will have to say
>>chomp ($Dupli_file);
>>
>>
>>
>>>print "The file you select is '$Dupli_file'\n"; open
>>>(Dupli_file,"$Dupli_file");
>>>  
>>>
>>When opening a file always check for failure like this open (Dupli_file,
>>$Dupli_file) or die "Cannot open $Dupli_file: $!\n"; $! will contain the
>>error string. For more info on $! (perldoc perlvar)
>>
>>
>>
>>>print "Please select the file you want to save the result to:\n";
>>>$Resu_file=;
>>>chomp;
>>>  
>>>
>>chomp ($Resu_file);
>>
>>
>>
>>>print "The result file is $Resu_file\n"; open
>>>(Resu_file,">$Resu_file");
>>>  
>>>
>>Check for failure
>>
>>
>>
>>>while ()
>>>{
>>>$orin_line=$_;
>>>while (){
>>>  
>>>
>>You are trying to read from a filehandle that has been  opened for
>>writing. This will throw a warning message.
>>
>>This logic will not work even if you open the result file for both
>>reading and writing. If the result file is empty to start with, the
>>execution path will never go into the while loop. while ()
>>will fail the first time, which means nothing gets written into
>>Resu_file. This makes it fail again the 2'nd time, 3'rd time ...
>>
>>
>>
>>>if("$_" eq "$orin_line")
>>>{
>>>next;
>>>}
>>>print Resu_file "$orin_line";
>>>};
>>>}
>>>}
>>>  
>>>
>>A hash is more suited for your job
>>#!/usr/bin/perl -w
>>use strict;
>>
>>chomp (my $dupli_file = );
>>chomp (my $res_file = );
>>
>>open (DUPLI, $dupli_file) or die "Failed to open $dupli_file: $!\n";
>>open (RESULT, ">$res_file") or die "Failed to open $res_file for
>>writing: $!\n";
>>
>>my %res_hash;
>>while () {
>>chomp;
>>unless ($res_hash{$_}++) {
>>print RESULT "$_\n";
>>}
>>}
>>close (DUPLI);
>>close (RESULT);
>>
>>
>
>  
>




Re: Regular expression

2002-10-04 Thread Robin Cragg

Hi Javeed ,

the last element of the array is $attt[$#attt]. If you have one line per 
element, that should do it.


R

At 14:24 04/10/2002 +0530, Javeed SAR wrote:

>I have the following output in array @attt
>I want the last line in a variable $out.
>What should the regular expression be?
>
>
>attribute type "SYNC_CHECK"
>   created 04-Oct-02.09:36:42 by javeed.clearuser@BLRK35ED
>   "for testing"
>   owner: HIS\javeed
>   group: HIS\clearuser
>   scope: this VOB (ordinary type)
>   value type: string
>   Attributes:
> SYNC_CHECK = "HELLO"
>
>
>Regards
>j


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




RE: Regular expression

2002-10-04 Thread Javeed SAR

Hi All,


I have the following output in array @attt
I want the last line, in this output  (SYNC_CHECK = "HELLO")  in a variable
$out.
What should the regular expression be?


attribute type "SYNC_CHECK"
  created 04-Oct-02.09:36:42 by javeed.clearuser@BLRK35ED
  "for testing"
  owner: HIS\javeed
  group: HIS\clearuser
  scope: this VOB (ordinary type)
  value type: string
  Attributes:
SYNC_CHECK = "HELLO"






Regular expression

2002-10-04 Thread Javeed SAR


I have the following output in array @attt
I want the last line in a variable $out.
What should the regular expression be?


attribute type "SYNC_CHECK"
  created 04-Oct-02.09:36:42 by javeed.clearuser@BLRK35ED
  "for testing"
  owner: HIS\javeed
  group: HIS\clearuser
  scope: this VOB (ordinary type)
  value type: string
  Attributes:
SYNC_CHECK = "HELLO"


Regards 
j