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!
Jenda Krynicky
From: "Traeder, Philipp" <[Email Removed]>
QUOTE
running the command:
date|awk '{print $2,$3}'

provides me with the output I require (i.e. the month and day, May
6).

any ideas? alternatively, does anyone have another way to
generate the date
in this format that I can assign to a variable?


Anyway - using a system call for getting the date look like overkill
to me. I'd use something like this:

my (undef, undef, undef, $mday, $mon) = localtime();

I would use

my ($mday, $mon) = (localtime())[3,4];

Both versions are of course just as good :-)

QUOTE
printf "Today is %s $mdayn",
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[ $mon ];

See perldoc -f localtime for detailed information.

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

William Black
Hello All,

OS: Windows

I have two perl scripts that need to run at the same time to preform a task.
Using perl how can I run both scripts at the same time on a windows
machine.

Ex) x.pl
y.pl

Regards,

William Black

_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page FREE
download! http://toolbar.msn.com/go/onm00200413ave/direct/01/

Shaunn Johnson
--belay that last transmission - i
--*have* to roll back to perl 5.6.x.
--sorry to jump the gun.

-X

--original post--
Is there a version of Oracle:DBD that will compile
with 5.8.0 or do I have to rollback to 5.6.1?

Bob Showalter
[Email Removed] wrote:
QUOTE
I have an application system command that is like tail -f in UNIX and
I want to say

x=1
while x < 10
do
'command'  append to log
print "n" append to log
issue HANGUP or KILL SIGNAL
x+=1
done

How do I issue a hangup signal to this process using perl?

I'm not sure I understand your problem, but the perl way to send a signal is
with the kill() function. The way to catch a signal is by installing a
handler using the %SIG hash.

perldoc -f kill
perldoc perlipc

Wiggins D Anconia
QUOTE
I need to look at a directory for about 90 seconds, and if a certain
file shows up, do something with it.  A pointer to a man page or any
reference would be appreciated.


perldoc -f opendir
perldoc -f readdir

A simple way to do this is to open the directory, loop over its contents
with readdir looking for your file. Then sleep for a second or some
interval, then read the contents again. Set a counter for the number of
iterations and then kill the while when it hits 90 (aka 90 seconds).
There are lots of ways this could be changed/improved, but it gets the
job done at least as well as the specification provided...

--pseudo code--

opendir or die
counter = 0
while counter < 90
list = readdir
if list contains file
process file
last

counter+1
sleep 1

close dir

http://danconia.org

John W. Krahn
Charles Farinella wrote:
QUOTE

I need to look at a directory for about 90 seconds, and if a certain
file shows up, do something with it.  A pointer to a man page or any
reference would be appreciated.

If you know the file name in advance then use one of the file test
operators like -e or maybe -s:

perldoc -f -X

Or you could use stat or open which will return undef and report an
error through $! if the file does not exist.

perldoc -f stat
perldoc -f open

If you only know part of the file name you could use glob or
opendir/readdir.

perldoc -f glob
perldoc -f opendir
perldoc -f readdir



John
--
use Perl;
program
fulfillment

In a message dated 5/10/2004 12:22:06 AM Eastern Daylight Time,
[Email Removed] writes:
QUOTE
Hi,

I have got two versions of a script to eliminate single line-feeds from
a file.  The first one does weird stuff - duplicating lines and messing
the text file up.  The second one works (I copied it from a Perl guide),
but I don't understand why.  I would much prefer the first one to work -
Can you tell me how to change the first one to make it work?

Also, I understand that the <> operator reads in one line at a time.  If
I wish to eliminate only triple line-feeds (nnn) and leave double and
single linefeeds, I presume <> won't work.  Without reading in the whole
file at once, how can I achieve this?

[codes snipped]


Working off your sample code, how about:

$filetobechanged = "iBook HD:Desktop Folder:tim.txt";
@ARGV = ($filetobechanged);
$^I = ".bak";
$/ = "nnn";
while (<>) {
s/nnn/;
print;
}

-will
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite

William Black
Hello I have the following driver script that calls two perl scripts to run
them asyn. The driver calls the open command for both scripts but the pgm
just hangs and never finishes. Does anyone know why?

Driver:
open (DAL,"C:temp7backuptemp1.pl");
open (DAL,"C:temp7backuptemp2.pl");

while (!-e "C:temp7backuptemp2.done"){}
while (!-e "C:temp7backuptemp1.done"){}

close(DAL);
close(STL);


temp1.pl
$i=0;
while ($i<500){$i += 1;}
system(echo complete > C:temp7backuptemp1.done);



temp2.pl
$i=0;
while ($i<500){$i += 1;}
system(echo complete > C:temp7backuptemp2.done);

William Black

_________________________________________________________________
Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage!
http://join.msn.com/?pgmarket=en-us&page=h...2ave/direct/01/

William Black
QUOTE
Hello I have the following driver script that calls two perl scripts to run
them asyn.  The driver calls the open command for both scripts but the pgm
just hangs and never finishes.  Does anyone know why?

Driver:
open (DAL,"|C:temp7backuptemp1.pl");
open (DAL,"|C:temp7backuptemp2.pl");

while (!-e "C:temp7backuptemp2.done"){}
while (!-e "C:temp7backuptemp1.done"){}

close(DAL);
close(STL);


temp1.pl
$i=0;
while ($i<500){$i += 1;}
system(echo complete > C:temp7backuptemp1.done);



temp2.pl
$i=0;
while ($i<500){$i += 1;}
system(echo complete > C:temp7backuptemp2.done);

William Black

William Black

_________________________________________________________________
Check out the coupons and bargains on MSN Offers! http://youroffers.msn.com

Nandkishore.Sagi
The file handlers are both DAL.

Change the file handler names.

-----Original Message-----
From: William Black [mailto:[Email Removed]]
Sent: Monday, May 10, 2004 8:50 AM
To: [Email Removed]
Subject: re: Piped input



QUOTE
Hello I have the following driver script that calls two perl scripts to

run
them asyn.  The driver calls the open command for both scripts but the
pgm
just hangs and never finishes.  Does anyone know why?

Driver:
open (DAL,"|C:temp7backuptemp1.pl");
open (DAL,"|C:temp7backuptemp2.pl");

while (!-e "C:temp7backuptemp2.done"){}
while (!-e "C:temp7backuptemp1.done"){}

close(DAL);
close(STL);


temp1.pl
$i=0;
while ($i<500){$i += 1;}
system(echo complete > C:temp7backuptemp1.done);



temp2.pl
$i=0;
while ($i<500){$i += 1;}
system(echo complete > C:temp7backuptemp2.done);

William Black

William Black

_________________________________________________________________
Check out the coupons and bargains on MSN Offers!
http://youroffers.msn.com


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

Rob Dixon
Hi Matthew.

Matthew Miller wrote:
QUOTE

Hello.  I've been hacking on Erik Oliver's rather
nice setext-to-html script, refining it beyond the
original interpretations of setext back in 2002.
I've run into two major snags that my limited
knowledge
of Perl is not allowing me to get past.  I'd
appreciate
any pointers or assistance anyone can offer.

I've included the complete script, and the example
setext file I test it with.

It would be useful to give some source line numbers so that
we could find the piece of code you're referring to.


QUOTE
The problems:

1.  The setext twodot-typotag ('..' on a line by
itself), is intended to indicate the logical end of
textual information in a file.  So, the script
should stop parsing the file when it encounters that
tag. [Side note: two periods beginning a line are
used  for other reasons, too, so _only_ two periods
alone on a line indicate the end of text].  However,
in
loop2  within the script, I've tried adding a simple:

if (/^..s*$/) {last;}

and it won't work.

I think you're talking about line 185, which reads:

if(/^..s*$/ ) {carp "Found twodot-ttn";}
# stop when the twodot-tt is encountered

Without using =~ to bind the regex to a spcific scalar
value, Perl will check the contents of $_, which isn't
being set in this context. You need

last if $data[$loop] =~ /^..s*$/;

QUOTE
2.  I'm trying to implement the note-typotag.  This
one is a two-part construction, consisting of a hot
tagged word in the text (word followed by
underscore: hot_ ) and a note tag to define the
content:
.. _hot Note content here.

I've hacked the href parsing piece to collect the
notes ok.  (Hrefs substitute a URL for the note
content and are otherwise identical.)  I can't seem
to find any variation on the hot-word parser that
allows me to tag both hrefs and notes.

I'm not clear what you mean here, but at a guess you're
talking about lines 137:

# href-tt finder: ^.. _href URL
if($data[$loop] =~ /^..s+_(S*)s+(.*//.*)s*/ ) {
:
}

and 155:

# note-tt finder: ^.. _href text
elsif($data[$loop] =~ /^..s+_(S*)s+(.*)s*/ ) {
:
}

For the latter, I'm guessing that the expansion for the
tag can contain embedded spaces but you want to trim trailing
space, in which case you want

$data[$loop] =~ /^..s+_(S+)s+(.*?)s*$/

For the hrefs, you're capturing all characters after the tag,
including trailing whitespace, as long as it includes a pair
of slashes. Do you really need to check for the slashes? I
would use the same regex as for notes and check separately
that the text was a well-formed URL. If you don't need to
do any checking then a simple

$data[$loop] =~ /^..s+_(S+)s+(S+)/

will grab the first block of non-space characters.

QUOTE
I'm really frustrated right now, so if I've left out
necessary details, I apologise.  Let me know and
I'll clarify.

HTH,

Rob

William M West
QUOTE
my $html = qq(<form name="register" id="something"
action="register/doregister.asp">);
(my $action) = ( $html =~ /action="([^"]*)"/ );

my reply would have been ::

my $foo = $blingblat =~ /action="(+*?)"/;

why the use of [^"] ? does this prevent bad data? - if
so how?

i am very curious :)

QUOTE
David Dorward



willy

thanks :)

David Dorward
On 11 May 2004, at 13:10, West, William M wrote:
QUOTE
(my $action) = ( $html =~ /action="([^"]*)"/ );

my reply would have been ::

my $foo = $blingblat =~ /action="(+*?)"/;

why the use of [^"] ?  does this prevent bad data? - if
so how?

My example says "zero or more characters which are not double quote
marks"
Your example throws an error message :)

Quantifier follows nothing in regex; marked by <-- HERE in m/action="(+
<-- HERE *?)"/ at test.pl line 2.

I think you wanted:

my $action = $html =~ /action="(.*?)"/;

Which is "any character" rather then "not a double quote mark".

That however, returns the success or failure of the regex rather then
the value captured. So if we put the brackets back in we get:

(my $action) = ($html =~ /action="(.*?)"/);

That gives the same as my example.

You example uses the non-greedy quantifier with any character, while
mine uses the greedy one 'not "'.

A quick test suggests that my version is very slightly faster (by
0.5-1.5 seconds in a loop of 1,000,000 applications). Its probably not
a very reliable test though.


--
David Dorward
<http://dorward.me.uk/>
<http://blog.dorward.me.uk/>

William M West
QUOTE

On 11 May 2004, at 13:10, West, William M wrote:
(my $action) = ( $html =~ /action="([^"]*)"/ );

my reply would have been ::

my $foo = $blingblat =~ /action="(+*?)"/;

why the use of [^"] ?  does this prevent bad data? - if
so how?

My example says "zero or more characters which are not double quote
marks"


ok. so this [^"] pattern as the effect of making the regex stop
at the next " that it comes across.




QUOTE
Your example throws an error message :)

Quantifier follows nothing in regex; marked by <-- HERE in m/action="(+
<-- HERE *?)"/ at test.pl line 2.

I think you wanted:

my $action = $html =~ /action="(.*?)"/;

yes :) actually i was thinking .+? but no matter :)

QUOTE

Which is "any character" rather then "not a double quote mark".

That however, returns the success or failure of the regex rather then
the value captured. So if we put the brackets back in we get:

my brain was not quite there... i'm used to using $1 $2 etc, and forgot
to finish that thought :)

QUOTE

(my $action) = ($html =~ /action="(.*?)"/);

That gives the same as my example.

using parentheses to capture matches is really neat :) i
did not know that you could do that.

QUOTE

You example uses the non-greedy quantifier with any character, while
mine uses the greedy one 'not "'.

A quick test suggests that my version is very slightly faster (by
0.5-1.5 seconds in a loop of 1,000,000 applications). Its probably not
a very reliable test though.



very informative! thank you

willy

James Edward Gray II
On May 11, 2004, at 2:04 PM, Peterson, Darren - Contractor.Westar wrote:

QUOTE
A few days ago I was reading about setting the value of the default
newline
sequence to either CRLF or LF.  I now need to do that but can't find
in my
books where that is.  I'd appreciate the name of the variable to alter
and
the method.

I believe you are looking for $/ and it is described in the 'perlvar'
document. Just search for INPUT_RECORD_SEPARATOR. Hope that helps.

James

John W. Krahn
William M West wrote:
QUOTE

David Dorward wrote:

(my $action) = ($html =~ /action="(.*?)"/);

That gives the same as my example.

using parentheses to capture matches is really neat :)  i
did not know that you could do that.

It is not the parentheses per se that capture matches, it is the list
context that the parentheses provide.

my ( $action ) = $html =~ /action="(.*?)"/;

my @actions = $html =~ /action="(.*?)"/;

print $html =~ /action="(.*?)"/;

All these examples provide list context to the expression $html =~
/action="(.*?)"/ but only the first one _requires_ parentheses.



John
--
use Perl;
program
fulfillment

William Black
I have the following code that starts two different processes/perl scripts.
The code correctly calls and processes the perl scripts, but never seems to
return back to the calling script for further processing. Does anyone have
any clue why this might happen?


#Create dal process

if ($OK == 0){

Win32::Process::Create($processobj0,"c:\Perl\bin\perl.exe",

"perl dal.pl",1,CREATE_NEW_CONSOLE,".")||
&Warn("Error Creating Dal Process. Exiting");

}



#open dal process

if ($OK == 0){

Win32::Process::Open($processobj0,my $pid0,1);

}



#Create stl process

if ($OK == 0){

Win32::Process::Create($processobj1,"c:\Perl\bin\perl.exe",

"perl stl.pl",1,CREATE_NEW_CONSOLE,".")||
&Warn("Error Creating Dal Process. Exiting");

}



#open dal process

if ($OK == 0){

Win32::Process::Open($processobj1,$pid1,1);

}





#Wait for stl download to complete

while (!-e "stl.done") {};

print "stl.done finishedn";



#kill stl process

Win32::Process::KillProcess($pid1,$exitcode);





#Wait for dal download to complete

while (!-e "dal.done") {};

print "dal.done finishedn";



#kill dal process

Win32::Process::KillProcess($pid0,$exitcode);

William Black

_________________________________________________________________
Express yourself with the new version of MSN Messenger! Download today -
it's FREE! http://messenger.msn.com/go/onm00200471ave/direct/01/

Ramprasad A Padmanabhan
On Thu, 2004-05-13 at 14:52, NYIMI Jose (BMB) wrote:
QUOTE
Hello,

I need to write a perl script that will run on solaris and the job of this script will be :

- read a mail from a predefined shared mail box (Outlook/Exchange Server)
- extract the mail attachment (text file)
- parse the content
- create an excel sheet (same content)

Any input is welcome ...

Jos.

perldoc MIME::Parser

Bob Showalter
NYIMI Jose (BMB) wrote:
QUOTE
I need to write a perl script that will run on solaris and the job of
this script will be :

- read a mail from a predefined shared mail box (Outlook/Exchange
Server)

Mail::IMAPClient or Mail::POP3Client

QUOTE
- extract the mail attachment (text file)
- parse the content

MIME::Parser

QUOTE
- create an excel sheet (same content)

Spreadsheet::WriteExcel

Wiggins D Anconia
QUOTE
NYIMI Jose (BMB) wrote:
I need to write a perl script that will run on solaris and the job of
this script will be :

- read a mail from a predefined shared mail box (Outlook/Exchange
Server)

Mail::IMAPClient or Mail::POP3Client

- extract the mail attachment (text file)
- parse the content

MIME::Parser


While were listing modules ;-), I will throw in Mail::Box, since it is
one distro that should be able to do both the accessing and parsing.

http://danconia.org

Wiggins D Anconia
QUOTE
-----Original Message-----
From: NYIMI Jose (BMB)
Sent: Thursday, May 13, 2004 11:23 AM
To: [Email Removed]
Subject: Extracting attachment from mail


Hello,

I need to write a perl script that will run on solaris and
the job of this script will be :

- read a mail from a predefined shared mail box
(Outlook/Exchange Server)
- extract the mail attachment (text file)
- parse the content
- create an excel sheet (same content)

Any input is welcome ...

Jos.




One more info about the flow:

* the original mail comes from an external user (outside our company):
no problem to that ...
* a MS Outlook rule will be set to forward this mail (with attachment)
to an unix user (solaris): good ?
* mails received by this unix user are all stored in the file named
/var/mail/username
* a perl script will be scheduled once per day to:

It sounds like you have a fair amount of control. Out of curiousity have
you considered having an alias established on the solaris box that
rather than dumps the message to a mail box, instead pipes it to a
program (aka your perl program). That program can then parse the
message directly on STDIN. This cuts out the need for the scheduler,
cleaning up the mail folder (since the message is handled directly and
then discarded (if desired)), and allows the file to be handled closer
to real time.


QUOTE
-filter messages coming from a predefined user (above external user)
-extract the attachment
-parse the attachment
-create the excel sheet
-send back the created excel file to a predefined address

* this script should also clean up its box /var/mail/username once per
day.
* the unix user that run the perl script is also the owner of
/var/mail/username file.

There are so many modules related to mail/mime in CPAN

Which one you think will fit in the best aforementioned functionality.


Well Mail::Box can certainly handle the above load, with the exception
of the scheduling, but I assume that would be cron, but it has a decent
learning curve. If you can dumb the script down to just taking the
message on STDIN then presumably any MIME aware message parser should be
sufficient, the other requirements at that point are just header parsing
which any mail handler should do about equally well. MB provides
message sending capabilities, and I like having one package that does it
all, but again any MIME sending module should be sufficient.

http://danconia.org

Jose Nyimi
QUOTE
-----Message d'origine-----
De: Wiggins d Anconia [mailto:[Email Removed]]
Envoy: jeudi 13 mai 2004 18:02
: NYIMI Jose (BMB); [Email Removed]
Objet: RE: Extracting attachment from mail

-----Original Message-----
From: NYIMI Jose (BMB)
Sent: Thursday, May 13, 2004 11:23 AM
To: [Email Removed]
Subject: Extracting attachment from mail


Hello,

I need to write a perl script that will run on solaris and
the job of this script will be :

- read a mail from a predefined shared mail box
(Outlook/Exchange Server)
- extract the mail attachment (text file)
- parse the content
- create an excel sheet (same content)

Any input is welcome ...

Jos.




One more info about the flow:

* the original mail comes from an external user (outside our
company):
no problem to that ...
* a MS Outlook rule will be set to forward this mail (with
attachment)
to an unix user (solaris): good ?
* mails received by this unix user are all stored in the file named
/var/mail/username
* a perl script will be scheduled once per day to:

It sounds like you have a fair amount of control. Out of curiousity
have
you considered having an alias established on the solaris box that
rather than dumps the message to a mail box, instead pipes it to a
program (aka your perl program).  That program can then parse the
message directly on STDIN.  This cuts out the need for the scheduler,
cleaning up the mail folder (since the message is handled directly and
then discarded (if desired)), and allows the file to be handled closer
to real time.

Nice! I will investigate on that.

Jos.

In a message dated 5/14/2004 3:05:01 PM Eastern Daylight Time,
[Email Removed] writes:
QUOTE
Hi there.
Brand new to PERL so please bear with me.  (I'm running Win32/Apache)

When I include the line
use strict;
in any perl program, I get the following error:
"Internal Server Error

Problem in on line 18. fix is:
my $str = DBI::neat_list(@row, 30, " ");


-will
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite

Andrew Gaffney
Roman Hanousek wrote:
QUOTE
Hi All

I have bunch of files that contain code like this:

What I am trying to do is match <ps:img and this /> then check that this
piece of code contains a alt= tag.


<ps:img page="/images/portal/arrow_down.gif" border="0"
width="9" height="6"
alt="${string['lists.list.sort.ascending.alt']}"
title="${string['lists.list.sort.ascending.alt']}" /


And if it doen't print the lines where it's missing to screen or file.

while($input =~ |<ps:img .+(alts*=s*".+")?.+/>|sgc) {
print "Missing ALTn" if(! defined $1);
}

That doesn't give you line numbers, but it does give you an idea of where to start.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.


Jeff 'Japhy' Pinyan
On May 18, James Edward Gray II said:

QUOTE
On May 18, 2004, at 9:30 AM, Andrew Gaffney wrote:

Doesn't the 'gc' modified make the whole think not as greedy? As a
side effect of continuation, doesn't it try to match as many times as
possible?

I'm not familiar with this, but my gut reaction is no.  Perhaps on of
the Regex experts can clear that up for us...

Correct. No modifier to a regex changes the greediness of the quantifiers
in the regex. All the /g modifier does is say:

1. if the regex is in list context, match, and then try to match again
following the first match, etc., until you stop
2. if the regex is in scalar context, match and return, but remember
where we left off -- the next time this regex is called with the /g
modifier, we will pick up where stopped. this position can also be
used with the G anchor.

Here are examples:

my $str = "japhy knows regexes";

@all_letters = $str =~ /w/g;
# @all_letters contains 17 elements: j,a,p,h,y,k,n,o,etc.
# and before you ask, NO, I DON'T need parens around w in there

while ($str =~ /(w+)/g) {
print "Got: '$1'n"; # Got: japhy; Got: knows; Got: regexes
}

if ($str =~ /(ww)/g) {
print "Two letters: '$1'n"; # 'ja'
if ($str =~ /G(.{5})/) {
print "Next five characters: '$1'n"; # 'phy k'
}
}

Once a /g match fails, G is cleared (G is linked to the pos() function;
that is, whatever pos($str) is equal to is the location in $str that G
anchors to).

*ALL* that the /c modifier does (and it only matters when used with the /g
modifier) is tell the regex engine NOT to clear G or pos() when a match
fails. Here's a method called the inchworm:

print "Got '$1'n" while
$str =~ /G"([^"]*)"s*/gc or
$str =~ /G'([^']*)'s*/gc or
$str =~ /G(S+)/gc;

This allows us to use $1 no matter which regex matches, and because all
three regexes have the /gc modifier, when the first one fails, it'll try
the second one, AT THE SAME LOCATION.

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

Bob Showalter
Peterson, Darren - Contractor.Westar wrote:
QUOTE
I'm trying to use fork and exec to kick-start other processes on a
Linux box.  As with Win32::Process::Create, I'd like to somehow
specify or point towards a working directory for the new process
since some data files are expected via relative path.  I actually
tried passing a compound command such as "cd
/home/otbsaf/OTBSAF/src/OTBSAF;./otbsaf" to exec to hope a directory
switch would happen as I intended.  The new process displays its
current directory and the directory shown was that from which the
perl script was running, not the hoped for otbsaf.

Just use Perl's chdir() after you fork:

defined(my $pid = fork) or die $!;
unless ($pid) {
chdir('/home/otbsaf/OTBSAF/src/OTBSAF') or die $!;
exec './otbsaf' or die $!;
}

James Edward Gray II
On May 17, 2004, at 11:16 PM, Andrew Gaffney wrote:

QUOTE
Roman Hanousek wrote:
Hi All I have bunch of files that contain code like this:
What I am trying to do is match <ps:img and this /> then check that
this
piece of code contains a alt= tag.
<ps:img page="/images/portal/arrow_down.gif" border="0"
width="9" height="6"
alt="${string['lists.list.sort.ascending.alt']}"
title="${string['lists.list.sort.ascending.alt']}"
/
And if it doen't print the lines where it's missing to screen or file.

while($input =~ |<ps:img .+(alts*=s*".+")?.+/>|sgc) {
print "Missing ALTn" if(! defined $1);
}

That doesn't give you line numbers, but it does give you an idea of
where to start.

Be careful. Matching HTML-style markup with regexen is surprisingly
tricky. I suspect the version above would not work well in many
instances. Remember .+ is super greedy, more so since you allow it to
swallow n as well. The above pattern should match the first <ps:img,
swallow the rest of ALL the data and then backup until it can find a
/>. That's probably not going to work out to well, in many cases.

Depending on how much is known about the tags, you might have more luck
with a pattern like:

m!<ps:img([^>]+)/>!g

From there it's pretty easy to check $1 for an alt="...", or whatever.

Hope that helps.

James

Andrew Gaffney
James Edward Gray II wrote:
QUOTE
On May 17, 2004, at 11:16 PM, Andrew Gaffney wrote:

Roman Hanousek wrote:

Hi All I have bunch of files that contain code like this:
What I am trying to do is match <ps:img and this /> then check that this
piece of code contains a alt= tag.
<ps:img page="/images/portal/arrow_down.gif" border="0"
width="9" height="6"
alt="${string['lists.list.sort.ascending.alt']}"
title="${string['lists.list.sort.ascending.alt']}" /
And if it doen't print the lines where it's missing to screen or file.


while($input =~ |<ps:img .+(alts*=s*".+")?.+/>|sgc) {
print "Missing ALTn" if(! defined $1);
}

That doesn't give you line numbers, but it does give you an idea of
where to start.


Be careful.  Matching HTML-style markup with regexen is surprisingly
tricky.  I suspect the version above would not work well in many
instances.  Remember .+ is super greedy, more so since you allow it to
swallow n as well.  The above pattern should match the first <ps:img,
swallow the rest of ALL the data and then backup until it can find a
/>.  That's probably not going to work out to well, in many cases.

Depending on how much is known about the tags, you might have more luck
with a pattern like:

m!<ps:img([^>]+)/>!g

From there it's pretty easy to check $1 for an alt="...", or whatever.

Hope that helps.

Doesn't the 'gc' modified make the whole think not as greedy? As a side effect
of continuation, doesn't it try to match as many times as possible?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.


James Edward Gray II
On May 18, 2004, at 9:30 AM, Andrew Gaffney wrote:

QUOTE
Doesn't the 'gc' modified make the whole think not as greedy? As a
side effect of continuation, doesn't it try to match as many times as
possible?

I'm not familiar with this, but my gut reaction is no. Perhaps on of
the Regex experts can clear that up for us...

James

Jeff 'Japhy' Pinyan
On May 18, John Pretti said:

QUOTE
# Create New CGI Object
my $q = new CGI;

# print form
print  $q->header,
$q->start_html,
$q->br,
$q->start_multipart_form,
$q->p("Select a  promotion directory:"),

Here's your first problem:

QUOTE
%label = ('hw'=>'..support_docs/HW',
'nw'=>'..support_docs/NW',
'sw'=>'..support_docs/SW',
'swmfis'=>'..support_docs/SW/MFIS',
'swunifi'=>'..support_docs/SW/Unifi',
'swwebcaaf'=>'../support_docs/SW/WEBCAAF_eforms');

You're defining this hash in the middle of your print() calls. That's
going to create the hash, but then print it out, and then your other
HTML-creating functions won't end up printing to anything, since you've
ended the print() statement with a semicolon.

QUOTE
$q->radio_group (
-name=> 'promdir',
-labels=>%label,
-default=>'selected',
-linebreak=>'true'),
$q->br,
$q->submit('Promote'),
$q->end_form,
$q->end_html;

[Tue May 18 13:46:01 2004] promote.cgi: Global symbol "%label" requires
explicit package name at /www/web/cgi-sec/merlin/promote.cgi line 36.

But this is the more important problem. You haven't declared %label as a
lexical variable, nor have you told Perl to let you use it as a global
variable. You want to do:

my $q = CGI->new;
my %label = ( ... ); # put the creation of the hash here

and then

print
$q->header,
$q->start_html,
$q->br,
$q->start_multipart_form,
$q->p("Select a promotion directory:"),
$q->radio_group (
-name=> 'promdir',
-labels=>%label,
-default=>'selected',
-linebreak=>'true'),
$q->br,
$q->submit('Promote'),
$q->end_form,
$q->end_html;

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

Jeff 'Japhy' Pinyan
On May 18, James Edward Gray II said:

QUOTE
On May 18, 2004, at 10:12 PM, Jason Dusek wrote:

What modules handle this? I have been digging around in CPAN all day...

Searching the CPAN for "array unique", the first match is the super
cool Tie::Array::Unique.

http://search.cpan.org/~pinyan/Tie-Array-U...-0.01/Unique.pm

Yes, I agree, it's super cool. (I'm the author.)

All you need to do is drop in:

use Tie::Array::Unique;
tie my(@array), 'Tie::Array::Unique';

into your code, and @array will automatically be guaranteed to hold only
unique elements. You have to download and install the module, of course,
but that's a simple process.

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

Jeff 'Japhy' Pinyan
On May 19, Ramprasad A Padmanabhan said:

QUOTE
#!/usr/bin/perl

my @arr = qw(a b c d a b e f );
print join(" " , sort @arr) . "n" . '#' x 50 . "n";
print join(" " , sort (uniq (@arr))) . "n";
exit 0;
sub uniq{keys%{{map{$_,1}@_}}}

Perl is not sorting the return values of the uniq() function, Perl is
using 'uniq' as the comparison function to sort(). This is *ALL* because
you have a space after the function name. If you did

sort(uniq(@arr))

or

sort +uniq(@arr)

you'd print the sorted unique values.

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

Keith
UNCLASSIFIED

I have had no problems compiling perl into executables on windows with the
Active State Perl Development kit.

http://www.activestate.com/Products/Perl_Dev_Kit/



-----Original Message-----
From: Ramprasad A Padmanabhan [mailto:[Email Removed]]
Sent: Thursday, May 20, 2004 3:07 AM
To: SAR, JAVEED (STSD)
Cc: Manish U; Beginners
Subject: RE: Perl2exe


Precisely,
I have even bought 'perl2exe' from indigostar. But we had such a
headache creating exes of some heavy files ( mostly those that required
XML::Parser or JABBER modules ) that we would give up and ship the
source.

Thanks
Ram
( BTW do U work for indigostar ? )

On Thu, 2004-05-20 at 12:19, SAR, JAVEED (STSD) wrote:
QUOTE
Have a look at this site

www.indigostar.com

Regards
javeed


******  There's no place like ~/  *******





-----Original Message-----
From: Ramprasad A Padmanabhan [mailto:[Email Removed]]
Sent: Thursday, May 20, 2004 12:13 PM
To: Manish U
Cc: Beginners
Subject: Re: Perl2exe


There is none of which I know, I too searched a lot about 2yrs ago. And
even the paid version is a pain to use. Converting perl files to
binaries is a hot topic of discussion but I dont think this is a very
successful idea

Ram

On Thu, 2004-05-20 at 11:41, Manish U wrote:
Hi,

Can any one give me the url where i can get a free version of
perl2exe.

Regards
Manish U

Disclaimer Statement:
----------------------------------------------------------------------
------

------------------------------------------------------------------------
--
The information contained in this message is confidential and
proprietary to
Datamatics Technologies Limited, Mumbai, India. It is intended only
for the
use of the individual or entity to whom it is addressed. If you are
not the
intended recipient, or the authorized agent thereof, you are hereby
notified
that any disclosure, use, distribution, dissemination or copying in
any form
of any information contained in this message is strictly prohibited.
If you
have received this message by mistake or error, please notify us
immediately
by return email to the sender or by fax on number +91-22-28291673 and
delete
all copies of the original message.

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

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






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

Jeff Westman
I just did this in fact using CSV.pm, worked great! See:

http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm




--- "DiGregorio, Dave" <[Email Removed]> wrote:
QUOTE
Does anyone know, what is the best way to retrieve text data from
an Excel
Spreadsheet?  I have tried the code below and it returns errors.
I can not
even get the name of the file to print!







#! usr/bin/perl -w



use strict ;

use Spreadsheet::ParseExcel ;

my $oExcel = new Spreadsheet::ParseExcel::Workbook ;



my $oBook = $oExcel->Parse('Excel/Test.xls') ;



print "File  :" , $oBook->{File} , "n" ;

print "Count  :" , $oBook->{SheetCount} , "n" ;

print "Author :" , $oBook->{Author} , "n" ;

I



Thanks



David







__________________________________
Do you Yahoo!?
Yahoo! Domains Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer

Kevin Old
I use the xls2csv utility that comes with Spreadsheet::ParseExcel.

Here's how I use it:

#!/usr/bin/perl

use warnings;
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::Utility qw(xls2csv);

my $content = xls2csv('myspreadsheet.xls', 'A5:Q164');

# $content is now the spreadsheet in csv format

my @lines = split/n/, $content;


HTH,
Kevin

On Fri, 2004-05-21 at 13:35, Jeff Westman wrote:
QUOTE
I just did this in fact using CSV.pm, worked great!  See:

http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm




--- "DiGregorio, Dave" <[Email Removed]> wrote:
Does anyone know, what is the best way to retrieve text data from
an Excel
Spreadsheet?  I have tried the code below and it returns errors.
I can not
even get the name of the file to print!







#! usr/bin/perl -w



use strict ;

use Spreadsheet::ParseExcel ;

my $oExcel = new Spreadsheet::ParseExcel::Workbook ;



my $oBook = $oExcel->Parse('Excel/Test.xls') ;



print "File  :" , $oBook->{File} , "n" ;

print "Count  :" , $oBook->{SheetCount} , "n" ;

print "Author :" , $oBook->{Author} , "n" ;

I



Thanks



David






 
__________________________________
Do you Yahoo!?
Yahoo! Domains  Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer
--

Kevin Old <[Email Removed]>

Lktee
Hi, now I design another way.

First I request user enter the directory want to search first, if the
directory exist in the system, script will search the entire directory. If
the filename is same will display out, else no result will return. If
directory not exist will request user try another directory.

So, the script like below:

#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
find ( &callback, "/$target");

my $target;
while (1) {
print "what directory want search?";
$target = <STDIN>
chmod $target;
if (-d $target) {
print "Yes, target is a directory.n";
next;
}
else{
print "No, $target not a directory.n";

sub callback{
print $File::Find::name, "n" if $File::Find::name =~
/File1$/;
}

May I know any wrong in my coding? Because I cannot run the script. Any idea
about this?

John W. Krahn
Lktee wrote:
QUOTE

Hi, now I design another way.

Hello,

QUOTE
First I request user enter the directory want to search first, if the
directory exist in the system, script will search the entire directory. If
the filename is same will display out, else no result will return. If
directory not exist will request user try another directory.

So, the script like below:

#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
find ( &callback, "/$target");

my $target;
while (1) {
print "what directory want search?";
$target = <STDIN
chmod $target;
if (-d $target) {
print "Yes, target is a directory.n";
next;
}
else{
print "No, $target not a directory.n";

sub callback{
print $File::Find::name, "n" if $File::Find::name =~
/File1$/;
}

May I know any wrong in my coding? Because I cannot run the script. Any idea
about this?

You need to put the find() call in the loop and put the sub callback {}
outside the loop and you also need to chomp the contents of $target.


#!/usr/bin/perl
use warnings;
use strict;
use File::Find;

sub callback {
print "$File::Find::namen" if $_ eq 'File1';
}

my $target;
while (1) {
print "what directory want search?";
chomp( my $target = <STDIN> );
unless ( -d $target ) {
print "No, $target not a directory.n";
next;
}
print "Yes, target is a directory.n";
find( &callback, $target );
}



John
--
use Perl;
program
fulfillment

Hi, John thanks you comment, the coding is work. But i'm detect have some small
problem in line 7 print "$File::Find::namen" if $_ eq 'File1'; I test as below
sample 2 is follow you coding. From here i detect nothing return from script.

But after i amend the coding become print "$File::Find::namen" if $_ = 'File1';
this work and return the result i expected. But why perl show "Found = in
conditional, should be == at ./callback line 7."? Any idea? I try put "==" to
replace "=", the result return like sample 2.

Sample 1
[root@localhost root]# ./callback
Found = in conditional, should be == at ./callback line 7.
what directory want search?perl
Yes, perl is a directory.
perl
perl/perl1
perl/123
perl/bash
perl/bash/perl1
perl/bash/123


Sample 2

[root@localhost root]# ./callback
what directory want search?perl
Yes, perl is a directory.
[root@localhost root]#

Jan Eden
Hi,

[Email Removed] wrote on 26.05.2004:

QUOTE
Hi, John thanks you comment, the coding is work. But i'm detect have
some small problem in line 7 print "$File::Find::namen" if $_ eq
'File1'; I test as below sample 2 is follow you coding. From here i
detect nothing return from script.

But after i amend the coding become print "$File::Find::namen" if
$_ = 'File1'; this work and return the result i expected. But why
perl show "Found = in conditional, should be == at ./callback line
7."? Any idea? I try put "==" to replace "=", the result return like
sample 2.

To check equality of numbers, use "==", to check the equality of strings, use "eq". A single "=" assigns a value to a variable.

HTH,

Jan
--
Either this man is dead or my watch has stopped. - Groucho Marx

John W. Krahn
[Email Removed] wrote:
QUOTE

Hi, John thanks you comment, the coding is work. But i'm detect have some small
problem in line 7 print "$File::Find::namen" if $_ eq 'File1'; I test as below
sample 2 is follow you coding. From here i detect nothing return from script.

But after i amend the coding become print "$File::Find::namen" if $_ = 'File1';
this work and return the result i expected. But why perl show "Found = in
conditional, should be == at ./callback line 7."? Any idea? I try put "==" to
replace "=", the result return like sample 2.

Perhaps you want this instead:

print "$File::Find::namen" if /File1$/;


John
--
use Perl;
program
fulfillment

Angie Ahl
Hi people

I'm trying to create a hash of arrays of arrays and I'm having a mind
twisting time with references.

my $key = "some_varying_text"
my %pathhash;
my @link = ($LinkUrl, $LinkTitle);

I'm trying to set $pathhash{$key} to an array that contains the array
@link.
ie there will be multiple @link arrays in $pathhash{$key}.

I just can't work out how to assign an array ref to an array ref to a
hash element. I think that's right.

Any clues anyone... please, 4 hours down and a lot of RTFM'ing hasn't
helped (quite the opposite actually;)

Angie

John W. Krahn
Angie Ahl wrote:
QUOTE

Hi people

Hello,

QUOTE
I'm trying to create a hash of arrays of arrays and I'm having a mind
twisting time with references.

my $key = "some_varying_text"
my %pathhash;
my @link = ($LinkUrl, $LinkTitle);

I'm trying to set $pathhash{$key} to an array that contains the array
@link.
ie there will be multiple @link arrays in $pathhash{$key}.

I just can't work out how to assign an array ref to an array ref to a
hash element. I think that's right.

Any clues anyone... please, 4 hours down and a lot of RTFM'ing hasn't
helped (quite the opposite actually;)

If @link is lexically scoped then use a reference:

$pathhash{ $key }[ 0 ] = @link;
# or
push @{ $pathhash{ $key } }, @link;


If not then you have to copy it to an anonymous array:

$pathhash{ $key }[ 0 ] = [ @link ];
# or
push @{ $pathhash{ $key } }, [ @link ];



John
--
use Perl;
program
fulfillment

Zentara
On Mon, 31 May 2004 19:26:26 +0800, [Email Removed] (Boon Chong Ang)
wrote:

QUOTE
Hi,

I am having problem to automatic feed in the data and solve the equation. Well, datatest.txt contains the data that I need to manipulate, the script is testing_abc1.pl and Matrix.pm is the one that I download from the net and use it at the local directory since I don't have the installation right. I would appreciate that some one would give me work around solutions or approach.


Well your script is a little too complex for me to easily figure out.

However, if you put

use diagnostics;

at the beginning of your script, you will get a helpful
message detailing the first error found in your script.




--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Rob Hanson
You could do create the string then strip the space. I think there was
something in the Perl Cookbook that was similar to this.

my $longlist = no_space(<<END_OF_LIST);
Clause1|
Clause2|
Clause3|
Clause4
END_OF_LIST

print $longlist;


sub no_space
{
my $txt = shift;
$txt =~ s/^s+//;
$txt =~ s/s*ns*//sg;
$txt =~ s/s+$//;
return $txt;
}

Rob

-----Original Message-----
From: [Email Removed] [mailto:[Email Removed]]
Sent: Tuesday, June 01, 2004 3:16 PM
To: [Email Removed]
Subject: Loading Scalar Vars with Text - Readability


Hi,
Adding Perl to the list of languages... and came across a question of
loading vars with very long strings...

Actually I am modifiying a prior employee's code and want to make it
more readable.

currently the code is such:
my $longlist = "Clause1|Clause2|Clause3|Clause4|...|ClauseN";

I would like to know why I can't make this more readable? Is it because
newline characters would be added to the mix? I would like to do
something like this:

my $longlist = "Clause1|
Clause2|
Clause3|
Clause4|
...|
ClauseN";

Please copy me directly on your response. T

Thanks,
Art Bahrs
[Email Removed]



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

Charles K. Clarkson
Boon Chong Ang <mailto:[Email Removed]> wrote:

: Hi,
: I am having problem to automatic feed in the data and solve
: the equation. Well, datatest.txt contains the data that I
: need to manipulate, the script is testing_abc1.pl and
: Matrix.pm is the one that I download from the net and use it
: at the local directory since I don't have the installation
: right. I would appreciate that some one would give me work
: around solutions or approach.


You really should begin again. You're are not using
strict. The use of 'foreach' over 'while' and of indenting
would improve the code readability and you need to pick more
descriptive names for variables.

I know this is a pain, but you are trying to walk without
ever having crawled. Let's take a look at some examples.
Here's a snippet you provided.

my $infile =$ARGV[0];
open (IN, "$infile") or die $!;
$outfile= "check.val";
open (OUT, "> $outfile") || die $!;

$count=0;
while (<IN>){
@mo=split(/s+/,$_);
push @da,$mo[0];
push @db,$mo[1];
push @dc,$mo[2];
$count++;
$total =$count
}
close(IN);

$outfile is not a lexical variable. Why leave 'my' off
here and use it on other variables? What are the rules you
use to determine which variables are lexical and which will
reside in the symbol table? The same questions need to be
asked for $count, @mo, @da, @db, @dc, and $total.

Why open the output file now? Why not wait until after
you closed the input file? Nothing is done with the output
file until then.

What is $count for? In fact, what is the point of $total?
The scalar value of @da gives the same value.

What does 'mo' mean? I assume English isn't your first
language, but can't you find something more meaningful than
'@mo', @da, @db, and @dc?

Use indentation when writing a loop and don't squash
all your white space together:

my $file = $ARGV[0] || die usage();
open FH, $file or die qq(Cannot open "$file": $!);

my( @da, @db, @dc );
while ( <FH> ) {
my @mo = split /s+/;
push @da, $mo[0];
push @db, $mo[1];
push @dc, $mo[2];
}

close FH;


$file= 'check.val';
open FH, "> $file" or die qq(Cannot open "$file": $!);

my $max = 4;
my $dif = @da - $max;
my $total = @da;

printf FH " dif %s max %s total %sn", $dif, $max, @da;
printf FH "total = %sn", @da;

foreach my $num ( 0 .. $#da ) {
print FH "$da[$num], $db[$num], $dc[$num]n";
$num++;
}

close FH;

Consider using 'foreach' in place of 'while' when appropriate.
Calculate math down to avoid repeated calculations. Here is
the code you provided.

while($dset ne $dif){
$inc=0;
$max=4;
$inc=$inc+$dset;
$max=$max+$dset;
while ($inc ne $max){
my $w=0;
while ($w le 1){
my $x=0;
while ($x le 1){
$a[$dset][$inc-$dset][$w][$x]=($da[$inc]**$x)*($db[$inc]**$w);
$x++;
}
$w++;
}
$inc++;
}
$dset++;
}

It might be written as:

my @a;
foreach my $dset ( 0 .. $#da - $max ) {
foreach my $i ( $dset .. $dset + 3 ) {
push @{ $a[$dset] }, [
[ 1, $da[$i], ],
[ $db[$i], $db[$i] * $da[$i], ],
];
}
}

Notice the use of white space in organizing the
algorithm. It also aids in readability. The variables are
now lexically scoped and we have eliminated $x and $w
completely.

Start your program again. Use this at the beginning
of the script.

#!/apps/perl/bin/perl -w

use strict;


Add a small amount of code and check for errors. Once
everything looks good, write a little more and then check
for errors. Keep writing that way until you get what you
want.

If you get stuck on some part ask us about just that
part. Be specific when you ask your question. Tell us what
you expect and tell us what you are getting instead.

Pretend that we don't have the time required to
download all your files and look them to find what the
problem might be and how to solve it.


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist


Rob Hanson
Thre ways...

exec('make');
system('make');
`make`;

The three differ slightly, you might want to check the docs.

Breifly...

exec - executes the command, but your Perl program ends where it is.
system - executes the command, waits for it to finish, returns the return
code.
`` (backticks) - executes the command, waits for it to finish, returns the
output (STDOUT, not STDERR).

Rob

-----Original Message-----
From: Sidharth [mailto:[Email Removed]]
Sent: Thursday, June 03, 2004 11:27 AM
To: [Email Removed]
Subject: how to execute make command


hi all,

i want to know how to execute makefile from the perl script ,its a sort
of urgent .

thank u all in advance...
----------------------------------------------------------------------------
-----------------------------------------------------
"There is nothing in a caterpillar that tells you it's going to be a
butterfly." - Anonymous

*********************************************
Sidharth M Patil
Engineer
Kyocera-Wireless (India) Pvt Ltd
5th Floor, Phase I, Divyashree Towers,
Guruppanapalya, Bannerghatta Road,
Bangalore-560072
Tel : 51106988 extn 5171
*********************************************

Bob Showalter
[Email Removed] wrote:
QUOTE
Hi There,
Any pointers to how to call "more" on a file in perl script.
I am writing one script which displays one report to user and then
asks some inputs.

User need to see complete file. To solve this, I thought I can call
`more <fileName> in the script and continue.
But looks loke it is not possible.

You didn't post your script, so I can only guess.

You can't use backticks, since they capture the output. If more is writing
to a non-tty (because you're capturing the output), it obviously has no way
to pause at a screenful, so it just passes the entire input to the output.

You need to use system() instead.

Also, it's customary to respect $ENV{PAGER}. I have my pager set to less,
for example.

Read "perldoc perlopentut" and search for PAGER to see an example of how to
do this kind of thing.

Wiggins D Anconia
QUOTE
hi,

i have to blast genes of human Y chromosome(104 genes)with genomes of non
human species to find which genes are conserved on Y and on non-Y
chromosomes in other species.and for each gene,its chromosome its 5' and
3'end location w.r.t. human Y gene and similarity percentage is also
required.
if done manually,it would amount for over 3000 blasts.it would be of
great
help if anyone could tell me the link to a perl script or similar
script ,
if available.


This is pretty topic specific, and you may get better help from the
bioperl list. For lots of good information you should check out:

http://bio.perl.org/
http://lists.perl.org/showlist.cgi?name=bioperl-l

http://danconia.org

Bob Showalter
[Email Removed] wrote:
QUOTE
Does anyone see anything logically wrong with my code b/c I am still
not receiving the correct data in the email.  The data is a # 1 when
it should be a listing of Exxxxx strings.

[snip]

QUOTE
Data    => print "@ftapes" );

This is assigning the return value of print(), which is a true/false. As
already pointed out to you, you want:

Data => "@ftapes"

or

Data => join("n", @ftapes)

Does anyone see anything logically wrong with my code b/c I am still not
receiving the correct data in the email. The data is a # 1 when it should
be a listing of Exxxxx strings.

thank you!

## Set pragmas

use strict;
use MIME::Lite;

## Set and edit variables

my $foreigntapes="/usr/local/log/foreign_tapes.log";
delete $ENV{'IFS'};
local $ENV{'PATH'} =
"/usr/epoch/bin:/usr/epoch/EB/bin:/usr/bin:/usr/sbin:/bin:/sbin";
#print $ENV{'PATH'},"n";

## Traverse through array and play with data

open (OUT, ">$foreigntapes") || die "could not open file:$!";
my @ftapes = grep s/^barcode=//, `evmvol -w label_state=1`;
print OUT "@ftapes";
#if ( -s @ftapes ) {
my $msg = MIME::Lite->new(
From => 'EDM01 <[Email Removed]>',
To => 'Derek Smith <[Email Removed]>',
Subject => "Foreign Tapes Found, now attmepting to
label",
Data => print "@ftapes" );
msg->send;

#foreach (@ftapes) {
#print $_;
#`evmlabel -l st_9840_acs_0 -t 9840S -b$_`
#}
close (OUT);
#} else {
# my $foo="/tmp/ftapes_runfile";
# open (RUNFILE, ">$foo") || die "could not open runfile:
$!;"
#}
#close (RUNFILE);

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






<[Email Removed]>
06/04/2004 10:58 AM
Please respond to cslyon


To: <[Email Removed]>, <[Email Removed]>
cc:
Subject: RE: sendmail


QUOTE
-----Original Message-----
From: [Email Removed] [mailto:[Email Removed]]
Sent: Friday, June 04, 2004 6:39 AM
To: [Email Removed]
Subject: sendmail

ok here it what I did and it is emailing sporadically or not at all???
Also it is not placing the array data into the email body???
it is like the if clause it not working.

thank you!

## Set pragmas

use strict;
use Mail::Sendmail;

## Set and edit variables

my $foreigntapes="/usr/local/log/foreign_tapes.log";
delete $ENV{'IFS'};
local $ENV{'PATH'} =
"/usr/epoch/bin:/usr/epoch/EB/bin:/usr/bin:/usr/sbin:/bin:/sbin";
#print $ENV{'PATH'},"n";

## Traverse through array and play with data

open (OUT, ">$foreigntapes") || die "could not open file:$!";
my @ftapes = grep s/^barcode=//, `evmvol -w label_state=1`;
print OUT "@ftapes";


I would try to test something else besides the handle. I know you can do
these types of tests against a file but a handle? Not sure if that is the
best way to do it. Besides, you are testing if the file exists and have a
nonzero size against a handle. Test the array maybe?



QUOTE
if ( -s OUT ) {
my %mailman = ( From    => 'EDM01 <[Email Removed]>',
To        => 'Derek Smith
<[Email Removed]>',
Subject    => "Foreign Tapes Found, now attmepting
to
label" ,
Message    =>  print OUT "@ftapes" );

Try this for the Message line instead:
Message => "@ftapes" );

You might also want to try MIME::Lite for sending this. I know there is a
bunch of discussion about Mail::Sendmail and having it work correctly and
everybody recommends MIME::Lite instead. I was using Mail::Sendmail for a
bunch of things and moved everything over to MIME::Lite. Works like a
charm!


QUOTE
sendmail (%mailman) or die $Mail::Sendmail::error;

foreach (@ftapes) {
print $_;
#`evmlabel -l st_9840_acs_0 -t 9840S -b$_`
}
close (OUT);
} else {
my $foo="/tmp/ftapes_runfile";
open (RUNFILE, ">$foo") || die "could not open runfile:
$!;"
#exit 0;
}
close (RUNFILE);


derek




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


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.