Help - Search - Member List - Calendar
Full Version: combinations
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44
Support our Sponsors!
Pablo Fischer
Thanks to all!

Im going to check the requirements (memory, CPU, etc).

Thanks!


El da Sunday 24 August 2003 1:45 a Pablo Fischer mand el siguiente correo:
QUOTE
Hi!

This maybe its not a Perl question.

I have a system (with 3 classes), that works in this order:


* Check in FTP for new files
* Download new Files
* Unzip those files (.zip files)
* Each file has 3000 lines, and there are like 10 files (30,000 lines), So
I need to parse the 30,000 lines and order them
* Parse File by File, and save the parssed file in a DB (MySql)
* Check to see if I need a backup of the Zip File
* Finish

How good its to do this in 10 seconds?
Exists a website with benckmark running times in Perl?

Thanks!
--
Pablo Fischer Sandoval ([Email Removed])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

--
Pablo Fischer Sandoval ([Email Removed])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

Rob Dixon
Pablo Fischer wrote:
QUOTE

This maybe its not a Perl question.

I have a system (with 3 classes), that works in this order:


* Check in FTP for new files
* Download new Files
* Unzip those files (.zip files)
* Each file has 3000 lines, and there are like 10 files (30,000 lines), So I
need to parse the 30,000 lines and order them
* Parse File by File, and save the parssed file in a DB (MySql)
* Check to see if I need a backup of the Zip File
* Finish

How good its to do this in 10 seconds?
Exists a website with benckmark running times in Perl?

Hi Pablo.

I'm not clear whether you already have this software written. But
as Oliver says, never think about trying to speed anything up
unless it's too slow. If you're trying to commit to a certain
performance level in a specification that you're writing, then go
and ask the people who care what the slowest acceptable performance
is. Whatever they say, look troubled, shake your head, mumble something
technical, and try to negotiate the required speed as low as you can.
Then when you go away and write it and it and it runs ten times faster
you'll be applauded as a hero.

By far the largest overhead here is going to be the FTP transfer,
which will depend on the type, quality and contention of your
connection. The next heaviest load will be the database access. Since
both of these are probably out of your control your best bet is to
just write the program, make it work, and publish it. It's very
unlikely that you'll be able to make much difference to the running
speed.

Good luck,

Rob

Pablo Fischer
I solved it :-)

@array = split("n", get_data());

foreach(@array) {
parse $_;
}

Now I can parse each line.

Thanks!
El da Sunday 24 August 2003 3:44 a Pablo Fischer mand el siguiente correo:
QUOTE
Hi!

I would like to parse data from a Field of a table (from a database in
MySql).

The data type of the filed its a TEXT.

An example of content:
[Email Removed]|arg1|arg2|arg3
[Email Removed]|arg1|arg2|arg3
[Email Removed]|arg1|arg2|arg3
[Email Removed]|arg1|arg2|arg3

So I would like to save this field and start parsing (selecting data) from
each line, like:

foreach(@result) {
parse $_;
}

How can I do this?

thanks!
Pablo
--
Pablo Fischer Sandoval ([Email Removed])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

--
Pablo Fischer Sandoval ([Email Removed])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

Pablo Fischer
I cant believe it..

Every message that I send I get an obvious answer by my self.

Thanks and sorry

I need to

$var =~ s/$s1/$s2/g

The cheat its in the 'g'.

Thanks!
El da Sunday 24 August 2003 7:44 a Pablo Fischer mand el siguiente correo:
QUOTE
Hi!

I have in $myvar a BIG HTML Text. I need to change some values to others.

For example, in one part I have

<b>Come and discover the OpenSource ###1###</b

I need to change all the ###1### values for $name, so It will be:

<b>Come and discover the OpenSource pablo</b

if the content of $name its "pablo".

I have tried with

$myvar =~ s/###1###/$name;

But no good results, some ###1### works and others no.

Does HTML::Parser will help me?

Thanks!
--
Pablo Fischer Sandoval ([Email Removed])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

--
Pablo Fischer Sandoval ([Email Removed])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

John W. Krahn
Mike Robeson wrote:
QUOTE

Hello,

Hello,

QUOTE
I am a relatively new PERL beginner and have been trying to work with
simple bioinformatics stuff. I have so far written some very useful but
simple bioinformatics scripts. However.... recently I have been trying
to work on a script to no avail. I have a text file whose contents are:

dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt

.... and so on...

I would like to turn that into this:

a g a t a g a t c g c a t c g a - - - - - - - - - - - - - - -
dog
a c g c t t c g a t a c g c t a g c t t a - - - - - - - - - -
cat
a g a t a t a c g g g t t  - - - - - - - - - - - - - - - - - - -
mouse

Notice that the sequence of letters varies however I need the lines in
the newly formed file to be equal in length by adding the appropriate
amount of dashes. For those in the know I am trying to convert a FASTA
file into a DCSE file.

I have been beating my head for the past 2 weeks and I cannot figure
out how to do this. I do not expect a complete answer (I would like to
try figuring this out on my own as much as possible) but rather some
guidance. Any detailed pseudo-code would be appreciated!!

According to your data this should work:

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30; # pad out to this length
while ( <DATA> ) {
unless ( s/^s*>// ) {
chomp;
my @char = ( split( // ), ( '-' ) x ( $len - length ) );
$_ = "@charn";
}
print;
}

__DATA__
QUOTE
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt




John
--
use Perl;
program
fulfillment

John W. Krahn
David --- Senior Programmer Analyst --- Wgo Wagner wrote:
QUOTE

#!perl -w
use strict;

my @MyWorka = ();
my $In = 0;
my $MyItem1 ;
my $MyItem2 ;

There is no reason to declare these variables with file scope as they
are only used inside the while loop.

QUOTE
my $MyMaxLen = 35;

while ( <DATA> ) {
chomp;
next if ( /^s*$/ );
if ( /^s+>(S+)/ ) {
$MyItem1 = $1;

my $MyItem1 = $1;

QUOTE
chomp($MyItem2 = <DATA>);

chomp( my $MyItem2 = <DATA> );

QUOTE
$In++;

What does this do? It isn't used anywhere else.

QUOTE
$MyItem2 =~ s/s+//g;
my $MyLen = length($MyItem2);
if ( $MyLen < $MyMaxLen ) {
my $MyExtra = $MyMaxLen - $MyLen;
$MyItem2 .= sprintf "%s", '-'x$MyExtra;

The use of sprintf is a bit redundant.

$MyItem2 .= '-' x $MyExtra;

QUOTE
}
@MyWorka = split(//,$MyItem2);
printf "%-2s"x$MyMaxLen , @MyWorka;
printf "n%-snn",
$MyItem1;

No need for printf here.

print join ' ', @MyWorka;
print "n$MyItem1nn",

QUOTE
}
}



John
--
use Perl;
program
fulfillment

Mike Robeson
I do not know what happend but the text didn't get formatted correctly
on the list. But this is how the out put should really have been:

a g a t a g a t c g c a t c g a - - - - - - dog
a c g c t t c g a t a c g c t a g c t t a - cat
a g a t a t a c g g g t t - - - - - - - - - mouse

That is, I want the edited sequence data and the name on the same line.


-Thanks
-Mike



In article <[Email Removed]>, [Email Removed] (John W. Krahn)
wrote:

QUOTE
Mike Robeson wrote:

Hello,

Hello,

I am a relatively new PERL beginner and have been trying to work with
simple bioinformatics stuff. I have so far written some very useful but
simple bioinformatics scripts. However.... recently I have been trying
to work on a script to no avail. I have a text file whose contents are:

dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt

.... and so on...

I would like to turn that into this:

a g a t a g a t c g c a t c g a - - - - - - - - - - - - - - -
dog
a c g c t t c g a t a c g c t a g c t t a - - - - - - - - - -
cat
a g a t a t a c g g g t t  - - - - - - - - - - - - - - - - - - -
mouse

Notice that the sequence of letters varies however I need the lines in
the newly formed file to be equal in length by adding the appropriate
amount of dashes. For those in the know I am trying to convert a FASTA
file into a DCSE file.

I have been beating my head for the past 2 weeks and I cannot figure
out how to do this. I do not expect a complete answer (I would like to
try figuring this out on my own as much as possible) but rather some
guidance. Any detailed pseudo-code would be appreciated!!

According to your data this should work:

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30;  # pad out to this length
while ( <DATA> ) {
unless ( s/^s*>// ) {
chomp;
my @char = ( split( // ), ( '-' ) x ( $len - length ) );
$_ = "@charn";
}
print;
}

__DATA__
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt



John


Zsdc
Mike Robeson wrote:

QUOTE
I do not know what happend but the text didn't get formatted correctly
on the list. But this is how the out put should really have been:

a g a t a g a t c g c a t c g a - - - - - -    dog
a c g c t t c g a t a c g c t a g c t t a -    cat
a g a t a t a c g g g t t - - - - - - - - -    mouse

That is, I want the edited sequence data and the name on the same line.

I'd hate to mess with your DNA (but just in case -- I, for one, welcome
our new super dog-cat-mouse mutant overlords) but I'll post two links
you may find interesting (if you don't already know them, that is).

First, you might take a look at the bioperl project: http://bioperl.org/
There's a mailing list you may find very useful, bioperl-l at
bioperl.org: http://www.bioperl.org/MailList.shtml

There's also a book, Beginning Perl for Bioinformatics written by James
Tisdall: http://www.oreilly.com/catalog/begperlbio/

I wish you good luck with your creations.

-zsdc.

John W. Krahn
Mike Robeson wrote:
QUOTE

In article <[Email Removed]>, [Email Removed] (John W. Krahn)
wrote:

According to your data this should work:

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30;  # pad out to this length
while ( <DATA> ) {
unless ( s/^s*>// ) {
chomp;
my @char = ( split( // ), ( '-' ) x ( $len - length ) );
$_ = "@charn";
}
print;
}

__DATA__
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt

I do not know what happend but the text didn't get formatted correctly
on the list. But this is how the out put should really have been:

a g a t a g a t c g c a t c g a - - - - - -    dog
a c g c t t c g a t a c g c t a g c t t a -    cat
a g a t a t a c g g g t t - - - - - - - - -    mouse

That is, I want the edited sequence data and the name on the same line.

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30;
my $name;
while ( <DATA> ) {
chomp;
unless ( s/^s*>(.+)// ) {
$name = $1;
my @char = ( split( // ), ( '-' ) x ( $len - length ) );
print "@char $namen";
}
}

__DATA__
QUOTE
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt




John
--
use Perl;
program
fulfillment

Zsdc
Pablo Fischer wrote:

QUOTE
I cant believe it..

Every message that I send I get an obvious answer by my self.

Thanks and sorry

There's no reason to be sorry. People reading your answers to your
questions can only learn, so in my opinion it's actually much better to
ask and then publicly answer your own questions than to keep it all to
yourself. It's kind of like writing a column about real world trouble
shooting and learning Perl with real examples.

-zsdc.

John W. Krahn
Mike Robeson wrote:
QUOTE

In article <[Email Removed]>, [Email Removed] (John W. Krahn)
wrote:

Mike Robeson wrote:

I do not know what happend but the text didn't get formatted correctly
on the list. But this is how the out put should really have been:

a g a t a g a t c g c a t c g a - - - - - -    dog
a c g c t t c g a t a c g c t a g c t t a -    cat
a g a t a t a c g g g t t - - - - - - - - -    mouse

That is, I want the edited sequence data and the name on the same line.

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30;
my $name;
while ( <DATA> ) {
chomp;
unless ( s/^s*>(.+)// ) {
$name = $1;
my @char = ( split( // ), ( '-' ) x ( $len - length ) );
print "@char    $namen";
}
}

__DATA__
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt

Thanks for the help!! I new it had to be simple... but I just didn't see
it! I just need to add some more code to it but I think I can take it
from here.

You can make that a bit more robust. :-)

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30;
while ( <DATA> ) {
unless ( /^s*$/ or s/^s*>(S+)// ) {
my $name = $1;
my @char = ( /[acgt]/g, ( '-' ) x $len )[ 0 .. $len - 1 ];
print "@char $namen";
}
}

__DATA__
QUOTE
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt




John
--
use Perl;
program
fulfillment

Paul Archer
Does anyone know of a pronunciation guide for the special variables and such
in Perl? I came up empty on Google. I've been learning Perl by reading and
doing, but I haven't talked to anyone face-to-face, so I'm not sure, for
example, if $_ is spoken "dollar-underscore", or if people typically say
something else--like "<=>" is a "spaceship", or "#!" is a "shebang".

Paul

Paul Johnson
Paul Kraus said:

QUOTE
Wow. I find that unusual in my 10 years of computer use/programming ...
I have always referred to $ and heard it referred to as "string".

Not that it matters but I find that definitely unusual :)

Do you have a background in BASIC? I think that in the UK at least it is
(was ?) common to refer to the $ in A$, for example, as "string" since
that is what it was, and it obviously had nothing to do with dollars.

But as far as Perl is concerned it is "dollar", and I am not aware of any
exceptions.

Now, as to whether $! is dollar-bang, dollar-pling,
dollar-exclamation-mark or anything else is not so easy.

You might find this link interesting:

http://www.eeng.brad.ac.uk/help/.faq/.unix/.pronun.html

But people, # is not a pound! ;-)

QUOTE
-----Original Message-----
From: Peter Scott [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 10:20 AM
To: [Email Removed]
Subject: RE: pronunciation guide


In article <000201c36b09$1f11be00$76fea8c0@pkraus>,
[Email Removed] (Paul Kraus) writes:
Not sure how to help you I do not that it is not very common to refer
to $ as dollar unless your talking about dollars. Generally when
dealing with computers it is a representation of the word string and is

spoken as such.

String-underscore.

I've never heard that.  I've been to dozens of meetings and conferences,
heard thousands of people talking about Perl, and never before have I
heard $_ referred to as anything other than "dollar underscore" or
occasionally "dollar underbar".

Strings are a small subset of possible values for scalars.  If $ were
mnemonic for anything, it would be "scalar", not "string".

--
Paul Johnson - [Email Removed]
http://www.pjcj.net

Jenda Krynicky
From: "mark sony" <[Email Removed]>
QUOTE
I have one file (say about 6000 lines) data divided into four
columns,say filename,owner,version etc.Now there would be two more
columns which shall be updated by multiple users according to the need
.Whats the best possible way of going forward? There would be about 30
users updating the empty columns ?

Have a look at DBD::CSV and DBD::AnyData

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

Jenda Krynicky
From: Pablo Fischer <[Email Removed]>
QUOTE
I have in $myvar a BIG HTML Text. I need to change some values to
others.

For example, in one part I have

<b>Come and discover the OpenSource ###1###</b

I need to change all the ###1### values for $name, so It will be:

<b>Come and discover the OpenSource pablo</b

if the content of $name its "pablo".

I have tried with

$myvar =~ s/###1###/$name;

I believe the actuall code looks like this, right?

$myvar =~ s/###1###/$name/;

You are missing a /g at the end to make sure you replace ALL
occurances even if there are several on one line. And you do not need
the backslash there:

$myvar =~ s/###1###/$name/g;

QUOTE
Does HTML::Parser will help me?

I don't think so. You are not really parsing HTML, you are just
replacing some patterns. And the fact that in this particual case you
have them in some HTML file is irrelevant.

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

Paul Kraus
Not sure how to help you I do not that it is not very common to refer to
$ as dollar unless your talking about dollars. Generally when dealing
with computers it is a representation of the word string and is spoken
as such.

String-underscore.

-----Original Message-----
From: Paul Archer [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 8:08 AM
To: [Email Removed]
Subject: pronunciation guide


Does anyone know of a pronunciation guide for the special variables and
such in Perl? I came up empty on Google. I've been learning Perl by
reading and doing, but I haven't talked to anyone face-to-face, so I'm
not sure, for example, if $_ is spoken "dollar-underscore", or if people
typically say something else--like "<=>" is a "spaceship", or "#!" is a
"shebang".

Paul

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

Peter Scott
In article <000201c36b09$1f11be00$76fea8c0@pkraus>,
[Email Removed] (Paul Kraus) writes:
QUOTE
Not sure how to help you I do not that it is not very common to refer to
$ as dollar unless your talking about dollars. Generally when dealing
with computers it is a representation of the word string and is spoken
as such.

String-underscore.

I've never heard that. I've been to dozens of meetings and conferences,
heard thousands of people talking about Perl, and never before have I
heard $_ referred to as anything other than "dollar underscore" or
occasionally "dollar underbar".

Strings are a small subset of possible values for scalars. If $ were
mnemonic for anything, it would be "scalar", not "string".

QUOTE
-----Original Message-----
From: Paul Archer [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 8:08 AM
To: [Email Removed]
Subject: pronunciation guide


Does anyone know of a pronunciation guide for the special variables and
such in Perl? I came up empty on Google. I've been learning Perl by
reading and doing, but I haven't talked to anyone face-to-face, so I'm
not sure, for example, if $_ is spoken "dollar-underscore", or if people
typically say something else--like "<=>" is a "spaceship", or "#!" is a
"shebang".
Paul Kraus
Wow. I find that unusual in my 10 years of computer use/programming ...
I have always referred to $ and heard it referred to as "string".

Not that it matters but I find that definitely unusual :)

Paul

-----Original Message-----
From: Peter Scott [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 10:20 AM
To: [Email Removed]
Subject: RE: pronunciation guide


In article <000201c36b09$1f11be00$76fea8c0@pkraus>,
[Email Removed] (Paul Kraus) writes:
QUOTE
Not sure how to help you I do not that it is not very common to refer
to $ as dollar unless your talking about dollars. Generally when
dealing with computers it is a representation of the word string and is

spoken as such.

String-underscore.

I've never heard that. I've been to dozens of meetings and conferences,
heard thousands of people talking about Perl, and never before have I
heard $_ referred to as anything other than "dollar underscore" or
occasionally "dollar underbar".

Strings are a small subset of possible values for scalars. If $ were
mnemonic for anything, it would be "scalar", not "string".

QUOTE
-----Original Message-----
From: Paul Archer [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 8:08 AM
To: [Email Removed]
Subject: pronunciation guide


Does anyone know of a pronunciation guide for the special variables and

such in Perl? I came up empty on Google. I've been learning Perl by
reading and doing, but I haven't talked to anyone face-to-face, so I'm
not sure, for example, if $_ is spoken "dollar-underscore", or if
people typically say something else--like "<=>" is a "spaceship", or
"#!" is a "shebang".


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

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

George Schlossnagle
On Monday, August 25, 2003, at 10:28 AM, Paul Kraus wrote:

QUOTE
Wow. I find that unusual in my 10 years of computer use/programming ...
I have always referred to $ and heard it referred to as "string".

Not that it matters but I find that definitely unusual :)

I've been to a number of conferences as well and never heard anyone
refer to $anything as anything other than 'dollar anything'.

George

Paul Kraus
Yep. One of our remaining distribution packages is still using business
basic. Sums it up :)

Paul

-----Original Message-----
From: Paul Johnson [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 10:54 AM
To: [Email Removed]
Cc: [Email Removed]; [Email Removed]
Subject: RE: pronunciation guide


Paul Kraus said:

QUOTE
Wow. I find that unusual in my 10 years of computer use/programming
... I have always referred to $ and heard it referred to as "string".

Not that it matters but I find that definitely unusual :)

Do you have a background in BASIC? I think that in the UK at least it
is (was ?) common to refer to the $ in A$, for example, as "string"
since that is what it was, and it obviously had nothing to do with
dollars.

But as far as Perl is concerned it is "dollar", and I am not aware of
any exceptions.

Now, as to whether $! is dollar-bang, dollar-pling,
dollar-exclamation-mark or anything else is not so easy.

You might find this link interesting:

http://www.eeng.brad.ac.uk/help/.faq/.unix/.pronun.html

But people, # is not a pound! ;-)

QUOTE
-----Original Message-----
From: Peter Scott [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 10:20 AM
To: [Email Removed]
Subject: RE: pronunciation guide


In article <000201c36b09$1f11be00$76fea8c0@pkraus>,
[Email Removed] (Paul Kraus) writes:
Not sure how to help you I do not that it is not very common to refer
to $ as dollar unless your talking about dollars. Generally when
dealing with computers it is a representation of the word string and
is

spoken as such.

String-underscore.

I've never heard that.  I've been to dozens of meetings and
conferences, heard thousands of people talking about Perl, and never
before have I heard $_ referred to as anything other than "dollar
underscore" or occasionally "dollar underbar".

Strings are a small subset of possible values for scalars.  If $ were
mnemonic for anything, it would be "scalar", not "string".

--
Paul Johnson - [Email Removed]
http://www.pjcj.net


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

Arthaey Angosii
QUOTE
Does anyone know of a pronunciation guide for the special variables and such
in Perl? I came up empty on Google. I've been learning Perl by reading and
doing, but I haven't talked to anyone face-to-face, so I'm not sure, for
example, if $_ is spoken "dollar-underscore", or if people typically say
something else--like "<=>" is a "spaceship", or "#!" is a "shebang".

My friend and I have been learning Perl in relative isolation from any
other experienced Perl programmers, so we've developed our own names for
these variables. I have no idea what the rest of the community uses, but
we have adopted $_ as "Dalton" -- a (mis)contraction of "DOLlar
UNderscore". :) We also pronounce $ in from of normal variables as
"scalar", and @ as "array" (or less frequently "list", if we feel like
being more accurate).

I have heard <=> as "spaceship" and <> as the "diamond" operator.

But I agree with you, it would be interesting to have some global list of
various ways Perl's special variables are called. :)


--
AA

Bob Showalter
T.S.Ravi Shankar wrote:
QUOTE
Dear all :

I see these lines in a perl program :

$pif = fork;
if($pid == 0) {
exec("hpxy  -s  .abc");
}else{
$pid1=wait;
}

I could understand that the fork is needed here to get into the child
process "hpxy" !! What is the need for the "wait" here ??  When will
the "else" loop be entered ??

After fork() there are two processes, parent and child. fork returns 0 to
the child, and the child's pid to the parent. So the "if" part is handling
the child, while the "else" part is handling the parent.

Basically, the child is exec()'ing a new program, while the parent is
calling wait(), which waits for the child to terminate.

The lines above are essentially equivalent to:

system("hpxy -s .abc");

Unless there's something else going on in the program that we're not seeing,
system() should be used instead of the code above, IMO.

Randal L. Schwartz
QUOTE
"Arthaey" == Arthaey Angosii <[Email Removed]> writes:

Arthaey> I have heard <=> as "spaceship" and <> as the "diamond" operator.

Larry's daughter Heidi came up with "diamond". And I'm the culprit
responsible for "spaceship".

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Paul Archer
4:53pm, Paul Johnson wrote:

QUOTE
Paul Kraus said:

Wow. I find that unusual in my 10 years of computer use/programming ...
I have always referred to $ and heard it referred to as "string".

Not that it matters but I find that definitely unusual :)

Do you have a background in BASIC?  I think that in the UK at least it is
(was ?) common to refer to the $ in A$, for example, as "string" since
that is what it was, and it obviously had nothing to do with dollars.

But as far as Perl is concerned it is "dollar", and I am not aware of any
exceptions.

Now, as to whether $! is dollar-bang, dollar-pling,
dollar-exclamation-mark or anything else is not so easy.

I thought it was a "bang for your buck"...



QUOTE
You might find this link interesting:

http://www.eeng.brad.ac.uk/help/.faq/.unix/.pronun.html

Good link, thanks.



QUOTE
But people, # is not a pound!  ;-)

Of course not, it's an octothorpe. Everyone knows that.


Paul

PS. What's with the Pauls here? Are Pauls particularly passionate about
Perl, or primarily pronunciation?

Paul Archer
8:58am, Randal L. Schwartz wrote:

QUOTE
"Arthaey" == Arthaey Angosii <[Email Removed]> writes:

Arthaey> I have heard <=> as "spaceship" and <> as the "diamond" operator.

Larry's daughter Heidi came up with "diamond".  And I'm the culprit
responsible for "spaceship".

--
And we (I, anyway) thank you. I got a good laugh out of that today when I

told my class that's what it was called--"no, really, that's it's name..."

Paul Archer

Peter Farrar
I thought it was only called 'string' in Applesoft...

Glad to hear I'm not the only one. My co-workers think I'm crazy.



|---------+---------------------------->
| | "Paul Kraus" |
| | <pkraus@pelsupply|
| | .com> |
| | |
| | 08/25/2003 09:02 |
| | AM |
| | Please respond to|
| | pkraus |
| | |
|---------+---------------------------->
QUOTE
--------------------------------------------------------------------------------------------------------------|
|                                                                                                              |

| To: "'Paul Archer'" <[Email Removed]>, [Email Removed] |
| cc: |
| Subject: RE: pronunciation guide |
QUOTE
--------------------------------------------------------------------------------------------------------------|




Not sure how to help you I do not that it is not very common to refer to
$ as dollar unless your talking about dollars. Generally when dealing
with computers it is a representation of the word string and is spoken
as such.

String-underscore.

-----Original Message-----
From: Paul Archer [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 8:08 AM
To: [Email Removed]
Subject: pronunciation guide


Does anyone know of a pronunciation guide for the special variables and
such in Perl? I came up empty on Google. I've been learning Perl by
reading and doing, but I haven't talked to anyone face-to-face, so I'm
not sure, for example, if $_ is spoken "dollar-underscore", or if people
typically say something else--like "<=>" is a "spaceship", or "#!" is a
"shebang".

Paul

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]


--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]





****** CONFIDENTIALITY NOTICE ******
NOTICE: This e-mail message and all attachments transmitted with it may
contain legally privileged and confidential information intended solely for
the use of the addressee. If the reader of this message is not the
intended recipient, you are hereby notified that any reading,
dissemination, distribution, copying, or other use of this message or its
attachments is strictly prohibited. If you have received this message in
error, please notify the sender immediately and delete this message from
your system. Thank you..

Paul Johnson
On Mon, Aug 25, 2003 at 06:08:05PM -0400, Paul Kraus wrote:

QUOTE
Why do you guys do when designing a software? Do your write out pseudo
code and then flow chart it?

I thought Perl was just executable pseudo code. And flow charts? I
haven't seen one of those for twenty years :-)

QUOTE
What do you do to keep track of notes and ideas and project information.

I am literally swamped with projects ranging from perl to BASIC to tbred
script development and I am getting messed up keeping everything
straight. I have about 20 different projects going right now and its
hard to remember where left off and on what. I am using Outlook tasks to
try and manage this buts a pain in the ass.

I bet it's hard. There's no way you can work on the development of
twenty projects simultaneously. Really, this is your problem. If you
can cut that number down to two, or at most three, but ideally one, then
you won't need software to remember what you were doing for you.

With twenty projects they are getting an average of 2 hours a week
maximum, I would assume (though I'm sure you don't work on all twenty
each week). That's not enough time to get up to speed, let alone do
anything productive. It's the human equivalent of thrashing. If you
want to actually get any work done you have to concentrate on a
particular project for a while. That way you will get through the
twenty much quicker.

You might like to take a look at some of the ideas from XP (that's
extreme programming). Type that into google and poke around for a bit.
They have some interesting ideas on these topics. Things that many
people have been doing for years, but are now becoming formalised and
recognised (by some) as good practice.

--
Paul Johnson - [Email Removed]
http://www.pjcj.net

Mike Robeson
OK, I feel like an idiot. When I initially asked for help with this I
just realized that I forgot two little details. I was supposed to add
the number of sequences as well as the length of the sequences at the
top of the output file.

That is this file:

QUOTE
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggtt


is relly supposed to be:

3 22
a g a t a g a t c g c a t c g a - - - - - - dog
a c g c t t c g a t a c g c t a g c t t a - cat
a g a t a t a c g g g t t - - - - - - - - - mouse

The '3' represents the number of individual sequences in the file (i.e.
dog, cat, mouse). And the 22 is the number of letters and dashes there
are. The length is already in the script as $len. I am able to get the
length listed at the top. However, I cannot find a way to have the
number of sequences (the 3 in this case) printed to the top.

Is there a way that I can just append to the outfile at the begining of
a file?

Sorry, about this. I didn't realize I forgot to include this info. I
guess I am to busy trying to learn PERL and I am not paying attention to
what I need PERL to do for me! :-)

-Thanks
-Mike


In article <[Email Removed]>, [Email Removed] (John W. Krahn)
wrote:

QUOTE
Mike Robeson wrote:

In article <[Email Removed]>, [Email Removed] (John W. Krahn)
wrote:

Mike Robeson wrote:

I do not know what happend but the text didn't get formatted correctly
on the list. But this is how the out put should really have been:

a g a t a g a t c g c a t c g a - - - - - -    dog
a c g c t t c g a t a c g c t a g c t t a -    cat
a g a t a t a c g g g t t - - - - - - - - -    mouse

That is, I want the edited sequence data and the name on the same line.

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30;
my $name;
while ( <DATA> ) {
chomp;
unless ( s/^s*>(.+)// ) {
$name = $1;
my @char = ( split( // ), ( '-' ) x ( $len - length ) );
print "@char    $namen";
}
}

__DATA__
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt

Thanks for the help!! I new it had to be simple... but I just didn't see
it! I just need to add some more code to it but I think I can take it
from here.

You can make that a bit more robust.  :-)

#!/usr/bin/perl
use warnings;
use strict;

my $len = 30;
while ( <DATA> ) {
unless ( /^s*$/ or s/^s*>(S+)// ) {
my $name = $1;
my @char = ( /[acgt]/g, ( '-' ) x $len )[ 0 .. $len - 1 ];
print "@char    $namen";
}
}

__DATA__
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt



John


David Wall
--On Monday, August 25, 2003 6:50 PM -0400 Mike Robeson
<[Email Removed]> wrote:

QUOTE
OK, I feel like an idiot. When I initially asked for help with this I
just realized that I forgot two little details. I was supposed to add
the number of sequences as well as the length of the sequences at the
top of the output file.

That is this file:

dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggtt

is relly supposed to be:

3    22
a g a t a g a t c g c a t c g a - - - - - -    dog
a c g c t t c g a t a c g c t a g c t t a -    cat
a g a t a t a c g g g t t - - - - - - - - -    mouse

The '3' represents the number of individual sequences in the file (i.e.
dog, cat, mouse). And the 22 is the number of letters and dashes there
are. The length is already in the script as $len. I am able to get the
length listed at the top. However, I cannot find a way to have the
number of sequences (the 3 in this case) printed to the top.

Here's one way (slightly altering John's solution), but it will use lots of
memory if the sequences are long.


#!/usr/bin/perl
use warnings;
use strict;

my ($name, $num_seq, @seq);
my $len = 30;
while ( <DATA> ) {
unless ( /^s*$/ or s/^s*>(S+)// ) {
my $name = $1;
my @char = ( /[acgt]/g, ( '-' ) x $len )[ 0 .. $len - 1 ];
push @seq, "@char $name";
$num_seq++;
}
}
{
local $" ="n";
print "$num_seqt$lenn@seqn";
}

__DATA__
QUOTE
dog
agatagatcgcatcga
cat
acgcttcgatacgctagctta
mouse
agatatacgggt


David Wall
--On Tuesday, August 26, 2003 12:36 AM +0200 Paul Johnson <[Email Removed]>
wrote:

QUOTE
You might like to take a look at some of the ideas from XP (that's
extreme programming).  Type that into google and poke around for a bit.
They have some interesting ideas on these topics.  Things that many
people have been doing for years, but are now becoming formalised and
recognised (by some) as good practice.

Here's an interesting place to get lost in:
http://c2.com/cgi/wiki?ExtremeProgramming

There's a Perl page there, too: http://c2.com/cgi/wiki?PerlLanguage

Zsdc
Anthony J Segelhorst wrote:

QUOTE
I am working on script to kill a process if it have been running for 45
minutes or more.

I am using a pstool called pslist to gather the data on the process.  This
out put looks like:
(...)

I started to build my array by doing:

@temparry = `"$lcf_tools\pslist EXCEL"`;
foreach $temp (@temparray){
($name,$pid,$pri,$thd,$hnd,$Mem,$usertime,$kerneltime,$elapsedtime) =
split(" ",$temp);

Maybe try:

/^EXCEL/ and @fields = split for `$lcf_tools/pslist EXCEL`;

Also, take a look at Proc::ProcessTable module on CPAN.

-zsdc.

Bryan Harris
Two quick questions for the gurus:

1. How are nested parenthesis in a match m// backreferenced? I have a
folder full of files:

file_3.0
file_3.0.1
file_3.0.1a
file_3.0.1b
file_3.0.10
file_3.1
file_3.1.1
file_3.2a

And I want the last one without any letters in the number (not an
alpha/beta). I have something like this:

$files = join " ", <file*>;
while ( m|(file_d+(.d+)b)|g ) { $thefile = $1; }

.... which seems to work (correctly returns file_3.1.1), but I'm not sure how
the nested parenthesis are supposed to be referenced. How would I get what
was matched by the inner set? Is this the best way to do this?

2. How do I set off a new process, not waiting or caring about any return
values?

$myApp = "/proj/mycoolexecutable";
$myOptions = "-f -n2 file1 file2";
# execute $myApp." ".$myOptions here, and do not wait for any return values


Thanks!

- Bryan

Marcos Rebelo
try

@temparry = `"$lcf_tools\pslist EXCEL"`;
foreach $temp (@temparray){
next if $temp !~ /EXCEL/;
($name,$pid,$pri,$thd,$hnd,$Mem,$usertime,$kerneltime,$elapsedtime) =
split(" ",$temp);
....
}


for avoiding errors, use 'strict' module

at beggining of the script do
use strict and define all variables.

MArcos
-----Original Message-----
From: Anthony J Segelhorst [mailto:[Email Removed]]
Sent: Tuesday, August 26, 2003 2:32 AM
To: [Email Removed]
Subject: filling an array


I am working on script to kill a process if it have been running for 45
minutes or more.

I am using a pstool called pslist to gather the data on the process. This
out put looks like:

C:Tivolilcfbinw32-ix86tools>pslist EXCEL

PsList 1.23 - Process Information Lister
Copyright © 1999-2002 Mark Russinovich
Sysinternals - www.sysinternals.com

Process information for CRP-DAY1-M73183:

Name Pid Pri Thd Hnd Mem User Time Kernel Time Elapsed
Time
EXCEL 4060 8 4 182 15640 0:00:00.190 0:00:00.220
0:11:22.721

C:Tivolilcfbinw32-ix86tools>


I started to build my array by doing:

@temparry = `"$lcf_tools\pslist EXCEL"`;
foreach $temp (@temparray){
($name,$pid,$pri,$thd,$hnd,$Mem,$usertime,$kerneltime,$elapsedtime) =
split(" ",$temp);

This is all wrong though, how I skip down to the line beginning with EXCEL
to start build my array.


Anthony J Segelhorst
Enterprise Systems Management Team
Email: [Email Removed]

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service._______________________________________________________________

Note: Please update your email address for this user to reflect the
new MeadWestvaco Corporation. MeadWestvaco employee email addresses
are in the format of [Email Removed]

This electronic message contains information from MeadWestvaco
Corporation or subsidiary companies, which may be confidential,
privileged or otherwise protected from disclosure. The
information is intended to be used solely by the recipient(s)
named. If you are not an intended recipient, be aware that
any review, disclosure, copying, distribution or use of this
transmission or its contents is prohibited. If you have
received this transmission in error, please notify MeadWestvaco
immediately at [Email Removed].
_______________________________________________________________________

Rob Dixon
"Anthony J Segelhorst" <[Email Removed]> wrote in message
news:[Email Removed]...
QUOTE
I am working on script to kill a process if it have been running for 45
minutes or more.

I am using a pstool called pslist to gather the data on the process.  This
out put looks like:

C:Tivolilcfbinw32-ix86tools>pslist EXCEL

PsList 1.23 - Process Information Lister
Copyright © 1999-2002 Mark Russinovich
Sysinternals - www.sysinternals.com

Process information for CRP-DAY1-M73183:

Name          Pid Pri Thd  Hnd    Mem    User Time  Kernel Time  Elapsed
Time
EXCEL        4060  8  4  182  15640  0:00:00.190  0:00:00.220
0:11:22.721

C:Tivolilcfbinw32-ix86tools


I started to build my array by doing:

@temparry = `"$lcf_tools\pslist EXCEL"`;
foreach $temp (@temparray){
($name,$pid,$pri,$thd,$hnd,$Mem,$usertime,$kerneltime,$elapsedtime) =
split(" ",$temp);

This is all wrong though, how I skip down to the line beginning with EXCEL
to start build my array.

I'm surprised this works at all with double quotes inside your backticks.
Here's how I'd write it.

HTH,

Rob



use strict; # always
use warnings; # usually

my $lcf_tools;

my @array = grep /^EXCEL/, `$lcf_tools\pslist EXCEL`;
chomp @array;

foreach (@temparray) {
my ($name,$pid,$pri,$thd,$hnd,$Mem,$usertime,$kerneltime,$elapsedtime) = split;
}

Rob Dixon
Zsdc wrote:
QUOTE

Anthony J Segelhorst wrote:

I am working on script to kill a process if it have been running for 45
minutes or more.

I am using a pstool called pslist to gather the data on the process.  This
out put looks like:
(...)

I started to build my array by doing:

@temparry = `"$lcf_tools\pslist EXCEL"`;
foreach $temp (@temparray){
($name,$pid,$pri,$thd,$hnd,$Mem,$usertime,$kerneltime,$elapsedtime) =
split(" ",$temp);

Maybe try:

/^EXCEL/ and @fields = split for `$lcf_tools/pslist EXCEL`;

This is the same as

foreach ( `$lcf_tools/pslist EXCEL` ) {
@fields = split if /^EXCEL/;
}

but IMO less clear.

QUOTE
Also, take a look at Proc::ProcessTable module on CPAN.

This module is for Unix processes. It looks like Anthony is on Windows
with backslashes in the path.

Cheers,

Rob

Rob Dixon
Marcos Rebelo wrote:
QUOTE
try

@temparry = `"$lcf_tools\pslist EXCEL"`;
foreach $temp (@temparray){
next if $temp !~ /EXCEL/;
($name,$pid,$pri,$thd,$hnd,$Mem,$usertime,$kerneltime,$elapsedtime) =
split(" ",$temp);
...
}

Better would be

next if $temp !~ /^EXCEL/;

which is 'doesn't start with' instead of 'doesn't contain'.

QUOTE
for avoiding errors, use 'strict' module

Absolutely. Yes. (applause). :)

Rob

Ramprasad A Padmanabhan
Anton Arhipov wrote:
QUOTE
Hi,

i've a string like "BLAH" (guotes included).
i need to control if the BLAH is in uppercase and then if it is in
uppercase truncate the quotes ("), so "BLAH" becomes BLAH.

any solutions?

Thx



You mean If you find any upper case word within quotes remove quotes right ?

$str = 'abc "BLAH" aaa "eef" ';
print "$strn";


$str=~s/"([^"]+)"/{(uc($1) eq $1)?$1:""$1"";}/ge;
print "$strn";


This should work
Ram

Marcos Rebelo
What is your real problem?

open(IN, "myCommand |");
open(OUT, ">$outputFileName");
print OUT join("", <IN>);
close OUT;
close IN;



-----Original Message-----
From: Ivan Novick [mailto:[Email Removed]]
Sent: Tuesday, August 26, 2003 1:47 PM
To: '[Email Removed]'; [Email Removed]
Subject: RE: redirecting the output of a command to a file



Is there no other way some perl syntax to redirect to a file the output of a
command?

-----Original Message-----
From: [Email Removed] [ mailto:[Email Removed]
<mailto:[Email Removed]> ]
Sent: Tuesday, August 26, 2003 7:14 AM
To: Ivan Novick; [Email Removed]
Subject: RE: redirecting the output of a command to a file


system("myCommand > myFile");
must work

-----Original Message-----
From: Ivan Novick [ mailto:[Email Removed]
<mailto:[Email Removed]> ]
Sent: Tuesday, August 26, 2003 1:11 PM
To: [Email Removed]
Subject: redirecting the output of a command to a file


Hi,

does anyone know syntax to run a command and redirect its output directly to

a file?

Equivalent to myCommand > myFile in shell

Thanks,

Ivan

Marcos Rebelo
the script are being called like

/usr/local/bin/perl5.8.0/bin/perl -w /proj/xpto.pl

I need the "/usr/local/bin/perl5.8.0/bin/perl"

The usual path is for a older version in this case. The perl path is in a
database that I don't see and I don't want to pass the perl path to the
script. That will be the answer if anything else works.

Marcos

-----Original Message-----
From: Paul Kraus [mailto:[Email Removed]]
Sent: Tuesday, August 26, 2003 4:19 PM
To: [Email Removed]; [Email Removed]
Subject: RE: Full path to the perl intrepter


If its in a UNIX env then just look at the she bang line :)

#!/usr/bin/perl

Then you could go to usr bin and see where perl is linked to.

If you have scripts that have a different line then just use perl to
search and replace with the correct line.

Paul

-----Original Message-----
From: [Email Removed] [mailto:[Email Removed]]

Sent: Tuesday, August 26, 2003 10:13 AM
To: [Email Removed]
Subject: Full path to the perl intrepter


I'm in a very old project and my scripts are calling other scripts. I
have 3 or 4 different perl version in the server. I need to call the
sub-scripts with the some version of perl that I'm using in the caller
script.

How to find the full path to the perl interpter that is being used?

Thanks
MArcos

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]

Christopher X66156 McMahon
On a Tandem, all processes begin with "$". As in: "$WRITER is
writing to the file; $BILL is the process that monitors the bank balance".
You'll definitely confuse Tandem people if you call the dollar sign
"string".
-Chris

-----Original Message-----
From: George Schlossnagle [mailto:[Email Removed]]
Sent: Monday, August 25, 2003 8:31 AM
To: [Email Removed]
Cc: [Email Removed]; [Email Removed]
Subject: Re: pronunciation guide


On Monday, August 25, 2003, at 10:28 AM, Paul Kraus wrote:

QUOTE
Wow. I find that unusual in my 10 years of computer use/programming ...
I have always referred to $ and heard it referred to as "string".

Not that it matters but I find that definitely unusual :)

I've been to a number of conferences as well and never heard anyone
refer to $anything as anything other than 'dollar anything'.

George

_
This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.

Paul Archer
Just a quick tip, which the docs mention that 'exists' and 'defined' will
let you know if a particular element of a hash exists, or is defined, they
work on arrays just as well.
(I didn't know that, but a student today asked, so I tried it out.)

Paul

John W. Krahn
Ivan Novick wrote:
QUOTE

Hi,

Hello,

QUOTE
does anyone know syntax to run a command and redirect its output directly to
a file?

Equivalent to myCommand > myFile in shell

open my $pipe, 'myCommand |' or die "Cannot open pipe from myCommand:
$!";
open my $fh, '>', 'myFile' or die "Cannot open myFile: $!";
print $fh while <$pipe>;
close $pipe or die "Cannot close pipe from myCommand: $!";


Or if myCommand outputs "binary" data.

open my $pipe, 'myCommand |' or die "Cannot open pipe from myCommand:
$!";
binmode $pipe;
open my $fh, '>', 'myFile' or die "Cannot open myFile: $!";
binmode $fh;
print $fh while read $pipe, $_, 1024;
close $pipe or die "Cannot close pipe from myCommand: $!";



John
--
use Perl;
program
fulfillment

Zsdc
Bryan Harris wrote:

QUOTE
... which seems to work (correctly returns file_3.1.1), but I'm not sure how
the nested parenthesis are supposed to be referenced.  How would I get what
was matched by the inner set?  Is this the best way to do this?

Everything is captured in $1, $2, $3... in the order of opening
parenthesis, from left to right.

QUOTE
2.  How do I set off a new process, not waiting or caring about any return
values?

$myApp = "/proj/mycoolexecutable";
$myOptions = "-f -n2 file1 file2";
# execute $myApp." ".$myOptions here, and do not wait for any return values

See:
perldoc -f fork
perldoc -f exec

-zsdc.

Janek Schleicher
Anton Arhipov wrote at Tue, 26 Aug 2003 13:02:00 +0300:

QUOTE
i've a string like "BLAH" (guotes included).
i need to control if the BLAH is in uppercase and then if it is in
uppercase truncate the quotes ("), so "BLAH" becomes BLAH.

s/"([A-Z]+)"/$1/g;

or on a POSIX operating system I would prefer the more appropriate
character class

s/"([[:upper:]]+)"/$1/g;


Greetings,
Janek

Zsdc
[Email Removed] wrote:

QUOTE
Thanks for replying zsdc.  The $1,$2 thing makes perfect sense now.

As for the fork/exec thing, those pages are a little over my head.  I
don't understandhow process signals and pipes work.

The fork concept can be quite confusing at first, but it is actually
quite simple, once you get used to it. Check out the output of this
little program:

#!/usr/bin/perl -w
print "STARTn";
fork;
print "ENDn";
sleep 1;

It prints:

START
END
END

"END" is printed twice because after the fork there are two processes
doing exactly the same. sleep 1 is also called twice but it results in
sleeping only 1 second, not 2 seconds, because both processes sleep at
the same time. I think it nicely shows what fork() basically does.

If the fork were the first statement then the program would behave like
it was always being run twice simultaneously. You can add "fork;" at the
beginning of some simple program to see what I mean.

Now, if you want both incarnations of your program to know which one is
which, you can check the value returned by the fork() function. The
parent process gets the PID of the child, while the child gets 0. If
fork returns undef it means that it couldn't fork at all.

The function exec() runs a command, just like system(), but it never
returns, so you can use fork() and then have the child exec() another
program, without the parent waiting for the child process to finish,
which is more or less equivalent to just using:

system 'some-program &';

in your code, but unfortunately it's not enough. More on that below.

QUOTE
Really, all I want the perl script to do is the equivalent of typing $myApp."
".$myOptions at the command line, sending its output to STDOUT.  This
script readsin all input files passed to it, determines which executable applies to
each, andlaunches that executable with that file as a parameter.  It may need to
launch 5 or 6processes, but I want it to gracefully exit when it's done launching and
not wait tillthose processes finish.  Does that make sense?  Is that even possible?

It is possible and it makes perfect sense, but it is not simple. First
of all, you could run your processes with:

system 'other-program &';

and unlike:

system 'other-program';

with '&' your program won't wait for the other-program to finish, but
the other-program process will die when your program (the parent
process) finishes.

Of course you want your program to finish without killing the child
processes in the process (pun definitely intended) and for that you need
your child processes to create new sessions with setsid().

You can take a look at Proc::Daemon module on CPAN, but it's not exactly
what you need, mostly because it redirects STDOUT to /dev/null, while
you want your processes to write to STDOUT (by the way, are you sure
about that? it can result in a total mess printed on your terminal) but
still you may want to read its source to see how it works:
http://search.cpan.org/src/EHOOD/Proc-Daemon-0.03/Daemon.pm

Try writing a subroutine like this and use it instead of system() to run
your processes:

use POSIX 'setsid';
sub forkrun ($) {
my $cmd = pop;
defined(my $pid = fork) or die "$0: fork: $!n";
unless ($pid) {
setsid or die "$0: setsid: $!n";
exec $cmd;
}
return $pid;
}

If you don't like the garbage printed on the terminal, then insert this
lines just before the call to exec:

open STDIN, '<', '/dev/null';
open STDOUT, '>', '/dev/null';
open STDERR, '>', '/dev/null';

Is that what you need?

--
ZSDC Perl and Systems Security Consulting

Paul Archer
4:09pm, Ramprasad A Padmanabhan wrote:

QUOTE
Paul Archer wrote:
Is there any (quick and easy) way to get a reverse range, like (10..1),
rather than a standard (1..10)? The catch is to *not* use 'reverse'.
I'm teaching Sun's perl course this week (DTP-250), and we were talking
about working on arrays. The book had an exercise that had the student
reverse an array by using pop (or shift, I don't remember). That section is
before we talk about 'reverse', and I thought you'd be able to do it like:
@array[0 .. $#array] = @array[$#array .. 0]
...but of course, having the range count down doesn't work.

Paul

IMHO this list is not for solving puzzles or doing school homework , It
is for people learning perl who are getting stuck due to pure perl problems
If I wanted a range (10..1) I will use reverse and why not. If you have
a better way tell me so that I can learn it


Actually, the description for this mailing list says "A list for beginning
Perl programmers to ask questions in a *friendly atmosphere*." (emphasis
added) I don't see anything about "No schoolwork", or "No puzzles"...

And the problem is not simply a puzzle, nor is it homework. If you had read
my post more carefully, you would see that I am 1) *teaching* the class, and
2) want to be able to show off one concept (the range operator) before we
have talked about another concept (the 'reverse' statement).

IM"H"O, if you want to be on a list that is "...for people learning perl who
are getting stuck due to pure perl problems..." then start one. I, on the
other hand, am staying here.

Paul

Jeff 'Japhy' Pinyan
On Aug 26, Paul Archer said:

QUOTE
Just a quick tip, which the docs mention that 'exists' and 'defined' will
let you know if a particular element of a hash exists, or is defined, they
work on arrays just as well.

Yeah, but I really think the semantics of them on arrays is iffy. I don't
use them on arrays... at least I try my best not to.

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

Ramprasad A Padmanabhan
Paul Archer wrote:
QUOTE
Is there any (quick and easy) way to get a reverse range, like (10..1),
rather than a standard (1..10)? The catch is to *not* use 'reverse'.
I'm teaching Sun's perl course this week (DTP-250), and we were talking
about working on arrays. The book had an exercise that had the student
reverse an array by using pop (or shift, I don't remember). That section is
before we talk about 'reverse', and I thought you'd be able to do it like:
@array[0 .. $#array] = @array[$#array .. 0]
...but of course, having the range count down doesn't work.

Paul

IMHO this list is not for solving puzzles or doing school homework , It
is for people learning perl who are getting stuck due to pure perl problems
If I wanted a range (10..1) I will use reverse and why not. If you have
a better way tell me so that I can learn it

Ram

Todd W.
"Paul Archer" <[Email Removed]> wrote in message
news:[Email Removed]...
QUOTE
Is there any (quick and easy) way to get a reverse range, like (10..1),
rather than a standard (1..10)? The catch is to *not* use 'reverse'.
I'm teaching Sun's perl course this week (DTP-250), and we were talking
about working on arrays. The book had an exercise that had the student
reverse an array by using pop (or shift, I don't remember). That section
is
before we talk about 'reverse', and I thought you'd be able to do it like:
@array[0 .. $#array] = @array[$#array .. 0]
...but of course, having the range count down doesn't work.

Paul

Reverse an array without using reverse():

with an array slice and map():
[trwww@waveright trwww]$ perl
@array = ( 1 .. 5 );
@array = @array[ map abs(), -$#array .. 0 ];
print( join("n", @array), "n" );
Ctrl-D
5
4
3
2
1

using splice(), pop(), and for():
[trwww@waveright trwww]$ perl
@array = ( 1 .. 5 );
splice( @array, $_, 0, pop @array ) for ( 0 .. $#array );
print( join("n", @array), "n" );
Ctrl-D
5
4
3
2
1

or the C way (but skipping the temporary variable):
[trwww@waveright perl]$ perl
@array = ( 1 .. 5 );
for ( $a = 0, $z = $#array; $a < $z; $a++, $z-- ) {
( $array[$a], $array[$z] ) = ( $array[$z], $array[$a] );
# @array[ $a, $z ] = @array[ $z, $a ]; # works too
}
print( join("n", @array), "n" );
Ctrl-D
5
4
3
2
1

perl is soooo cool.

Todd W.

Eurospace Szarindar
Hi,

@normal = (0,1,2,3,4,5,6,7,8,9);
foreach (0..$#normal) { unshift @reverse, (shift @normal) };


this also works fine.

Michel

-----Message d'origine-----
De: Paul Archer [mailto:[Email Removed]]
Date: mardi 26 aot 2003 21:45
: [Email Removed]
Objet: reverse range (10..1)


Is there any (quick and easy) way to get a reverse range, like (10..1),
rather than a standard (1..10)? The catch is to *not* use 'reverse'.
I'm teaching Sun's perl course this week (DTP-250), and we were talking
about working on arrays. The book had an exercise that had the student
reverse an array by using pop (or shift, I don't remember). That section is
before we talk about 'reverse', and I thought you'd be able to do it like:
@array[0 .. $#array] = @array[$#array .. 0]
...but of course, having the range count down doesn't work.

Paul

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.