Help - Search - Member List - Calendar
Full Version: combinations
WebHost Freaks 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!
Shawn McKinley
Does anyone know of a way to find the default printer?

I have found there are some ways to do it on a single
platform, but I was wondering if there is a way to do
it without any OS proprietary code.

I have a script that will need to find the default
printer on Win(98 - XP), *nix, and Mac(OS 8 and 9).

TIA,
Shawn

Agftech Lists
YOu may use Printer.pm
I have only used with Linux but seems the Printer() print_command() take
the platform dependent arguments.
You can use control statements and take care of that.
There might be a better answer, I'll look forward to it.

HTH


On Thu, 2003-12-18 at 08:35, Shawn McKinley wrote:
QUOTE
Does anyone know of a way to find the default printer?

I have found there are some ways to do it on a single
platform, but I was wondering if there is a way to do
it without any OS proprietary code.

I have a script that will need to find the default
printer on Win(98 - XP), *nix, and Mac(OS 8 and 9).

TIA,
Shawn


______________________
Aman Raheja
AGF Technologies
http://www.agftech.com
______________________

Jeff Westman
Eric Walker <[Email Removed]> wrote:

QUOTE
I got it so I need a counter which sends me to a for loop instead of a
foreach.  Thanks..

perlknucklehead

I believe that 'for' and 'foreach' are completely interchangable. I remember
reading somewhere that one was a synonym for the other.

Maybe someone who is more familiar with the internals can confim that.


-Jeff


QUOTE
On Thu, 2003-12-18 at 17:07, Paul Johnson wrote:
On Thu, Dec 18, 2003 at 04:57:26PM -0700, Eric Walker wrote:

Hello all
While traversing a loop across and array, how can I access array
positions further down the array, like say if I am on a loop looking
at
position 23, how can I check the value of say position 24 or 32 while
my
loop counter is on position 23.

Hmmm?  Add 1 or 9 to your loop counter?

Or have you not actually got a loop counter?  If that is the case the
easiest solution is probably to get one.

Or have I completely misunderstood?  Showing the code is usually more
productive than simply describing the problem.

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




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




__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

Jeff Westman
Paul Johnson <[Email Removed]> wrote:

QUOTE
On Thu, Dec 18, 2003 at 07:26:03PM -0500, Randy W. Sims wrote:
On 12/18/2003 7:00 PM, James Edward Gray II wrote:
On Dec 18, 2003, at 5:48 PM, Mike Blezien wrote:

Hello,

been trying to come up with a way, while going through a loop to
alternate a table cell color <td></td>....


See if this gets you thinking along the right lines:

my $odd = 1;
while (<>) {    # some kind of loop...
if ($odd) {
# do something
$odd = 0;
}
else {
# do something else
$odd = 1;
}
}


or

my $alt;
while (<>) {    # some kind of loop...
if ($alt = !$alt) {
# do something
}
else {
# do something else
}
}

or

while (<>) {
if ($|--) {
# do something

HUH?????? Why are you decrementing the $OUTPUT_AUTOFLUSH variable as an
'alternate' for loop???!

Sorry, I don't follow you here.........


-JW



QUOTE
}
else {
# do something else
}
}

Oh, no.  Hold on.  On second thoughts ...

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


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

Randy W. Sims
On 12/20/2003 8:21 AM, David Inglis wrote:

QUOTE
I am reading in a csv file and it has a control character ^M at the end
of each line how can I remove these charaters, I have tried the following
and had no success.

$a=~s/^M//;
$a=~s/^M//;


Any help appreciated thanks.



^M is the carriage return. Try s/x0D//;

Regards,
Randy.

Tom Kinzer
tr/015//;

-Tom Kinzer

-----Original Message-----
From: Randy W. Sims [mailto:[Email Removed]]
Sent: Thursday, December 18, 2003 8:05 PM
To: David Inglis
Cc: [Email Removed]
Subject: Re: how to remove a ^M charaters from a variable


On 12/20/2003 8:21 AM, David Inglis wrote:

QUOTE
I am reading in a csv file and it has a control character ^M at the end
of each line how can I remove these charaters, I have tried the following
and had no success.

$a=~s/^M//;
$a=~s/^M//;


Any help appreciated thanks.



^M is the carriage return. Try s/x0D//;

Regards,
Randy.


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

Jaffer
Hai David,

I don't where you tried this
have you tried this in NT or in UNIX?

$a="jaffer^";
$a=~s/^M//; This works in NT
print $a;

But it wont works in Unix.

Try this way in Unix $a=~s/15//g;

Let me know if any....

Thank you
jaffer


-----Original Message-----
From: David Inglis [mailto:[Email Removed]]
Sent: Saturday, December 20, 2003 6:51 PM
To: [Email Removed]
Subject: how to remove a ^M charaters from a variable



I am reading in a csv file and it has a control character ^M at the end
of each line how can I remove these charaters, I have tried the following
and had no success.

$a=~s/^M//;
$a=~s/^M//;


Any help appreciated thanks.


--
Regards



David Inglis



--
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
Tom Kinzer wrote:
QUOTE

tr/015//;

This will do nothing to the string. It will just return the
number of zero, one and five characters it finds.

Control-M is

"cM"
or
"x0D"
or
"15"
or
"r"

To get 'tr' to delete the characters it finds you need the /d
modifier.

tr/15//d

will do the trick.

Cheers,

Rob

Dan Muey
QUOTE
Hai David,

I don't where you tried this
have you tried this in NT or in UNIX?

$a="jaffer^";
$a=~s/^M//; This works in NT
print $a;

But it wont works in Unix.

Sure it does:
(unless you're talking goofy data of a binary hexy sort of thing,
which you might be since I completely missed this post ;p )

perl -Mstrict -we 'my $v = "HI^MHI";print "$vn";$v =~ s/^M//;print "$vn";'
HI^MHI
HIHI

If you just want to kill the carat and not necessariy 'carat uppercase M' just do
s/^//;

You might want to add a g so it gets them all.

Dmuey

QUOTE

Try this way in Unix $a=~s/15//g;

Let me know if any....

Thank you
jaffer


Tom Kinzer
right - my bad. what i mean, not what i say!

thanks rob.

-Tom Kinzer

-----Original Message-----
From: Rob Dixon [mailto:[Email Removed]]
Sent: Friday, December 19, 2003 3:07 AM
To: [Email Removed]
Subject: Re: how to remove a ^M charaters from a variable


Tom Kinzer wrote:
QUOTE

tr/015//;

This will do nothing to the string. It will just return the
number of zero, one and five characters it finds.

Control-M is

"cM"
or
"x0D"
or
"15"
or
"r"

To get 'tr' to delete the characters it finds you need the /d
modifier.

tr/15//d

will do the trick.

Cheers,

Rob



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

Dan Muey
QUOTE

What's unethical about it?  What's wrong with posting it in multiple
places?!!  Not everyone on this list is a member of that list (and
vice-versa).  It is also very possible that someone on this list
doesn't know the answer she needs (or doesn't bother to respond).


Nothing really, I think the idea was it would have been nice to know:
[example]
I posted to the foo@bar list and they said "use Crypt::OpenPGP;"
but I'm not sure how to use that for my idea.
[/example]

Sara, are you wanting to encryp data? If so I like Crypt::OpenPGP but
there are many many methods to accomplish that.
Or are you interested in posting to a list and then the list not
displaying your adress on the web archive?

HTH

DMuey

Dan Anderson
QUOTE
"r"

Caveat: Only on *nix systems. Otherwise n is 0x1512 and not 0x12.

-Dan

Dan Anderson
On Fri, 2003-12-19 at 11:54, Dan Anderson wrote:
QUOTE
"r"

Caveat: Only on *nix systems.  Otherwise n is 0x1512 and not 0x12.

That should read Otherwise n can be 0x1512 -- i.e. on Windoze boxen.
On Macs it's something different.

-Dan

Agftech Lists
I'd found this here
http://www.unixblog.com/quick_unix_tips/remove_m_with_vi.php
------------
You can try this on multiple files
perl -pi -e 's/15//g' files
------------




On Sat, 2003-12-20 at 07:21, David Inglis wrote:
QUOTE
I am reading in a csv file and it has a control character ^M at the end
of each line how can I remove these charaters, I have tried the following
and had no success.

$a=~s/^M//;
$a=~s/^M//;


Any help appreciated thanks.


--
Regards



David Inglis



______________________
Aman Raheja
AGF Technologies
http://www.agftech.com
______________________

Tom Kinzer
Also to address the root cause, the OP said it was on the end of every line.
I would check the whole system - depending on the journeys and gyrations the
CSV file goes through before you get it. An intelligent use of ASCII ftp
(binary bad) and/or chomp will usually take care of any of the
cross-platform weirdness on the end of your lines.

-Tom Kinzer

-----Original Message-----
From: agftech lists [mailto:[Email Removed]]
Sent: Friday, December 19, 2003 9:00 AM
To: [Email Removed]
Subject: Re: how to remove a ^M charaters from a variable


I'd found this here
http://www.unixblog.com/quick_unix_tips/remove_m_with_vi.php
------------
You can try this on multiple files
perl -pi -e 's/15//g' files
------------




On Sat, 2003-12-20 at 07:21, David Inglis wrote:
QUOTE
I am reading in a csv file and it has a control character ^M at the end
of each line how can I remove these charaters, I have tried the following
and had no success.

$a=~s/^M//;
$a=~s/^M//;


Any help appreciated thanks.


--
Regards



David Inglis



______________________
Aman Raheja
AGF Technologies
http://www.agftech.com
______________________


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

Douglas Lentz
David Inglis wrote:

QUOTE
I am reading in a csv file and it has a control character ^M at the end
of each line how can I remove these charaters, I have tried the following
and had no success.

$a=~s/^M//;
$a=~s/^M//;


Any help appreciated thanks.




This is an MS-DOSsy file, where each line is terminated by the famous

CR/LF combination. "^M" is the carriage return. Between the regex
slashes ("the jungle") "^" means "beginning of line", so what you have
instructed regex to do is erase any capital "M" that happens to occur at
the beginning of a line.

If you have a copy of the program dos2unix around, it will take care of
this for you, otherwise you can try $a =~ s/x0D//;

which means replace any CR you find with null. HTH.

Ajey
if its a unix file,.open in vi
:%s/ctrl+v ctrl+m//g
(where ctrl+v and ctrl+m gives the ^M character.)

cheers


On Fri, 19 Dec 2003, Douglas Lentz wrote:

QUOTE
David Inglis wrote:

I am reading in a csv file and it has a control character ^M at the end
of each line how can I remove these charaters, I have tried the following
and had no success.

$a=~s/^M//;
$a=~s/^M//;


Any help appreciated thanks.




This is an MS-DOSsy file, where each line is terminated by the famous
CR/LF combination. "^M" is the carriage return. Between the regex
slashes ("the jungle") "^" means "beginning of line", so what you have
instructed regex to do is erase any capital "M" that happens to occur at
the beginning of a line.

If you have a copy of the program dos2unix around, it will take care of
this for you, otherwise you can try $a =~ s/x0D//;

which means replace any CR you find with null. HTH.


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


Chetak Sasalu
Hi,

I have one more requirement, The last STATUS which occurs just prior to
the file end should not be followed by a page break character. How can I
code this in perl?

Thanks John! For giving me the fish and, more importantly, the fishing
net(pod) :-D

-Chetak

-----Original Message-----
From: John W. Krahn [mailto:[Email Removed]]

Sent: Saturday, December 20, 2003 3:33 PM
To: [Email Removed]
Subject: Re: How to write a page break character.


Chetak Sasalu wrote:
QUOTE


Hi,

Hello,

QUOTE
I want to search for the word "status" in a group of files in a
directory and replace it with "statusn^L" where ^L is a page break

chatacter, In vi I can type it in using cntrl+l.


I want to do this by


perl -p -i.old -e 's/^STATUS$/STATUSn(page break character)/' *


How can I "write" the page break character (^L) on command line?

Both perlop.pod and perlre.pod list the escape sequences that Perl (and
C) use for printing control characters.

perl -i.old -pe's/^STATUS$/STATUSnf/' *

Or:

perl -i.old -pe's/^STATUS$/STATUSncL/' *

Or:

perl -i.old -pe's/^STATUS$/STATUSn14/' *

Or:

perl -i.old -pe's/^STATUS$/STATUSnx0C/' *



John
--

use Perl;
program
fulfillment

--

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



Confidentiality Notice


The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [Email Removed] immediately
and destroy all copies of this message and any attachments.

John W. Krahn
Chetak Sasalu wrote:
QUOTE

Chetak Sasalu wrote:

I want to search for the word "status" in a group of files in a
directory and replace it with "statusn^L" where ^L is a page break
chatacter, In vi I can type it in using cntrl+l.

I want to do this by

perl -p -i.old -e 's/^STATUS$/STATUSn(page break character)/' *

How can I "write" the page break character (^L) on command line?

I have one more requirement, The last STATUS which occurs just prior to
the file end should not be followed by a page break character. How can I
code this in perl?

That is going to be a little more difficult. If you can fit the file(s)
into memory then:

perl -i.old -0777pe's/^STATUS$(?=.*?STATUS)/STATUSnf/sgm' *



John
--
use Perl;
program
fulfillment

Rob Dixon
Chetak Sasalu wrote:
QUOTE

From: John W. Krahn [mailto:[Email Removed]]
Sent: Saturday, December 20, 2003 3:33 PM
To: [Email Removed]
Subject: Re: How to write a page break character.

Chetak Sasalu wrote:

Hi,

Hello,

I want to search for the word "status" in a group of files in a
directory and replace it with "statusn^L" where ^L is a page break
chatacter, In vi I can type it in using cntrl+l.

I want to do this by

perl -p -i.old -e 's/^STATUS$/STATUSn(page break character)/' *

How can I "write" the page break character (^L) on command line?

Both perlop.pod and perlre.pod list the escape sequences that Perl (and
C) use for printing control characters.

perl -i.old -pe's/^STATUS$/STATUSnf/' *

Or:

perl -i.old -pe's/^STATUS$/STATUSncL/' *

Or:

perl -i.old -pe's/^STATUS$/STATUSn14/' *

Or:

perl -i.old -pe's/^STATUS$/STATUSnx0C/' *

I have one more requirement, The last STATUS which occurs just prior to
the file end should not be followed by a page break character. How can I
code this in perl?

Thanks John! For giving me the fish and, more importantly, the fishing
net(pod) :-D

Hi Chetak.

Unfortunately this isn't as easy as you might think, because you have to read
up to the next STATUS line or the end of the file to discover whether the
current STATUS is the last in the file. There are other ways, such as
reading all through the file once first counting how many STATUS lines there
are and then reading it again, printing a FF after all but the last. But since
I don't know how big your file is I can't suggest that. The code below should
work, although it's untested. I'll wait for you to come back with questions
if you don't understand it straight off. It simply reads the file in chunks
that /end/ with a line containing STATUS and prints "nf" before it unless
it's the first chunk.


use strict;
use warnings;

my $lines;
my $chunk;

local $^I = '';

while (<>) {

$lines .= $_;
next unless /^STATUS$/;

print "nf" if $chunk++;
print $lines;
$lines = '';
}

print $lines;


HTH,

Rob

Daniel Staal
--As off Monday, December 22, 2003 9:15 AM +0530,
[Email Removed] is alleged to have said:

QUOTE
I have one more requirement, The last STATUS which occurs just
prior to the file end should not be followed by a page break
character. How can I code this in perl?

--As for the rest, it is mine.

Just to turn this on it's head: what follows the other status lines?
(Besides the page break.) Would it be possible to think of the page
break being prior to it (and therefore not connected to the STATUS
line)?

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes. This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

Chetak Sasalu
Daniel, You hit the STATUS on its head !!!!

What follows after the status, is another test case starting with the
following line.

STATUS:
^L
4.1 (-) madmad: Testing reliable nuts.

I did it my way...the morons way, I chucked the file into a scalar
variable, reset the $RS ($) so that $ in the reg exp matched the end of
the file.

Thanks,
Daniel.
-----Original Message-----
From: Daniel Staal [mailto:[Email Removed]]

Sent: Monday, December 22, 2003 8:22 PM
To: Perl Newbies
Subject: RE: How to write a page break character.- one more question


--As off Monday, December 22, 2003 9:15 AM +0530,

[Email Removed] is alleged to have said:

QUOTE
I have one more requirement, The last STATUS which occurs just prior

to the file end should not be followed by a page break character. How

can I code this in perl?

--As for the rest, it is mine.

Just to turn this on it's head: what follows the other status lines?

(Besides the page break.) Would it be possible to think of the page

break being prior to it (and therefore not connected to the STATUS

line)?

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you are
expressly allowed to retransmit, quote, or otherwise use the contents
for non-commercial purposes. This copyright will expire 5 years after
the author's death, or in 30 years, whichever is longer, unless such a
period is in excess of local copyright law.
---------------------------------------------------------------

--

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



Confidentiality Notice


The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [Email Removed] immediately
and destroy all copies of this message and any attachments.

Drieux
On Dec 24, 2003, at 3:38 PM, Robert Steck wrote:
[..]
QUOTE
Ah, but my friend Drieux, you apparently did not have the unalloyed
pleasure
of growing up in Texas in the 1950's, a time when the Texas
Legislature came
within a whisker of passing a law stipulating that from now on PI would
equal exactly 3.14, full stop -- no more of that Commie-inspired
unending
decimal places for us Texans!
[..]


I can appreciate that Texas is a bit behind the times,
but the gag was first put forward in indiana in 1897.
<http://www.urbanlegends.com/legal/indiana_pi_bill.html>

But then again, mathematicians are the canaries in the
coal mine, watch for us to move, we will be leaving
before the Jews....


ciao
drieux

---

Owen Cook
On Thu, 25 Dec 2003, Stijn DM wrote:

QUOTE
I installed a script called "megauploader" successfully and did some layout
work in the php documents
to fit it to my own needs.

Now I also would like to change the layout in the progress bar window. The
problem
is that this is a CGI document and I am somewhat inexperienced in Perl.

Each time I make a modification in the CGI file (using a text editor) and I
save it, I get a Internal
Server Error. I think because of the fact that I didn't compile the original
script to a new cgi file.

Is there any way that I can modify the cgi files or that I can compile the
perl
files to cgi again? This might seem a really dumb question, but as I said,
I'm new on the issue.



When you modify a program, you have to modify it so that the
"Perl" recompiles correctly.

I suggest that you are making an incorrect "Perl" statement when you
change the script.

Why don't you post the lines you want to change, and the lines after you
changed them. maybe someone can tell you the error of your ways.

Also it would be helpful if you had Perl installed on your computer for
testing or even learning perl.

If you had perl you could say
"perl -c megauploader.cgi" to see if it will still compile before
you put it on the server.

Good luck



Owen

R. Joseph Newton
Stijn DM wrote:

QUOTE
Hi,

I installed a script called "megauploader" successfully and did some layout
work in the php documents
to fit it to my own needs.

Now I also would like to change the layout in the progress bar window. The
problem
is that this is a CGI document and I am somewhat inexperienced in Perl.

Each time I make a modification in the CGI file (using a text editor) and I
save it, I get a Internal
Server Error. I think because of the fact that I didn't compile the original
script to a new cgi file.

Is there any way that I can modify the cgi files or that I can compile the
perl
files to cgi again? This might seem a really dumb question, but as I said,
I'm new on the issue.

Thanks for your help,
Stijn

I'm going to take a wild peep into my crystal ball, and guess that you are
FTP'ing in binary mode from a Windows or Mac. Use ASCII mode when FTP'ing
scripts to an unknown or different OS. The different systems use different
escape sequences for their newlines, and ASCII mode will handle the translation
transparently.

Joseph

Dan Muey
QUOTE
I want to be able to return a true or false value from a
function in a module and populate the $! variable with the
specific errors. Is this possible? Is there documentation on
how to do this? I can find docs on how to use $! but not how
to set it. Thanks for any help -Ken

Did anyone ever reply to this post?
I couldn't find it in the archives and I thinnk it's a pretty good question.

For instance would it be 'safe' and 'proper', and 'ok', etc... to do somethign like:

sub whatever {
my $foo = shift;
undef $!;
if($foo eq 'bar') { return 1; }
else { $! = "Foo must equal bar";return 0; }
}

TIA

Dan

Randal L. Schwartz
QUOTE
"Dan" == Dan Muey <[Email Removed]> writes:

I want to be able to return a true or false value from a
function in a module and populate the $! variable with the
specific errors. Is this possible? Is there documentation on
how to do this? I can find docs on how to use $! but not how to
set it. Thanks for any help -Ken

Dan> Did anyone ever reply to this post? I couldn't find it in
Dan> the archives and I thinnk it's a pretty good question.

Dan> For instance would it be 'safe' and 'proper', and 'ok',
Dan> etc... to do somethign like:

Dan> sub whatever { my $foo = shift; undef $!; if($foo eq 'bar') {
Dan> return 1; } else { $! = "Foo must equal bar";return 0; } }

$! is for system-call-related errors that can be mapped to errno
return values. I don't see "Foo must equal bar" fits that definition.
Perhaps you want to look at the "Exception" module.

Having said that, you can set $! to a numeric value, and it'll return
that number in a numeric context, and the appropriate error text in a
string context. Rememeber that $! is just a thin wrapper over errno
though, so any system-call-related activity will change it.

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

Daniel Staal
--As off Monday, December 29, 2003 12:54 PM -0600, Dan Muey is
alleged to have said:

QUOTE
I want to be able to return a true or false value from a
function in a module and populate the $! variable with the
specific errors. Is this possible? Is there documentation on
how to do this? I can find docs on how to use $! but not how
to set it. Thanks for any help -Ken

Did anyone ever reply to this post?
I couldn't find it in the archives and I thinnk it's a pretty good
question.

There were several responses, I can forward them to you if you really
want them. Basically it boiled down to: "Read 'perldoc perlvar' for
how and possible values.", and "Are you sure you want to do that?".

QUOTE
For instance would it be 'safe' and 'proper', and 'ok', etc... to
do somethign like:

sub whatever {
my $foo = shift;
undef $!;
if($foo eq 'bar') { return 1; }
else { $! = "Foo must equal bar";return 0; }
}

"Foo must equal bar" is not a valid value for $!, most likely. :-)
For what you are doing here I would really prefer you either 'die' or
'warn', depending on what severity you think the problem is. (You
could of course 'croak' or 'carp' instead, as applicable.)

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes. This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

Dan Muey
QUOTE
--As off Monday, December 29, 2003 12:54 PM -0600, Dan Muey is
alleged to have said:

I want to be able to return a true or false value from a
function in
a module and populate the $! variable with the specific errors. Is
this possible? Is there documentation on how to do this? I
can find
docs on how to use $! but not how to set it. Thanks for
any help -Ken

Did anyone ever reply to this post?
I couldn't find it in the archives and I thinnk it's a pretty good
question.

There were several responses, I can forward them to you if you really
want them.  Basically it boiled down to: "Read 'perldoc perlvar' for
how and possible values.", and "Are you sure you want to do that?".

For instance would it be 'safe' and 'proper', and 'ok',
etc... to do
somethign like:

sub whatever {
my $foo = shift;
undef $!;
if($foo eq 'bar') { return 1; }
else { $! = "Foo must equal bar";return 0; }
}

"Foo must equal bar" is not a valid value for $!, most likely. :-)
For what you are doing here I would really prefer you either 'die' or
'warn', depending on what severity you think the problem is.  (You
could of course 'croak' or 'carp' instead, as applicable.)

Daniel T. Staal

I'll probably just do something else besides setting it. If I
must have a variable then I can just have my own little $error
variable to use fo rthat purpose. Thanks for the offer to forward them,
I'll just look at the perldoc and go from there.

Thanks

Dan

Rajesh Dorairajan
Rob,

Sorry for the ambiguity in my email. Your solution worked right away.

To answer your questions, @links is an array that contains the list of links
in the page as www:mechanize::links objects. The argument that I used in the
GET method is a hack that actually is available in LWP::UserAgent get
method. Since www::mechanize basically inherits the get method from LWP it
enables me to follow a link and save the content as a file. Much like
right-clicking on a link and "Save target as.." in IE.

Thanks a lot for your help

Rajesh

QUOTE
-----Original Message-----
From: Rob Dixon [mailto:[Email Removed]]
Sent: Thursday, December 25, 2003 4:59 AM
To: [Email Removed]
Subject: Re: How to extract the full URL from a relative link
using WWW:
: Mecha nize


Rajesh Dorairajan wrote:

I am using WWW::Mechanize to create a configuration file
from a website and
my script needs to go through a web-page and copy a
specific links into a
configuration file. I am using $m->links method that
returns the list of
links from a page. However, I am not able to get the fully
qualified URL
such as http://www.domain.com/dir1/dir12/file1.html. Instead I get
/dir1/dir12/file.html. Please forgive me if this doesn't
make sense. I am
giving the code below for more clarity:

my $obj = WWW::Mechanize->new();
my $url = "http://www.domain.com/dir1";
.
.

for my $link ( @links ) {
my $url = $link->url;
$obj->get ( $url );
my @urls = $obj->links;


$obj->get( $urls[1]->url,
":content_file"=>"$dir/tmp/tmpfile.cert" );
.
.

print CRL "[INPUT_SECTION_$count]n";
print CRL "LOCATION=".$urls[2]->url."nn"; #This is
where I need the
fully qualified URL instead of the relative URL that I get currently
$count++;
}

I looked up a lot on the web before sending this mail. I am
not able to find
any documentation that points to this. Any help will be
deeply appreciated.

Hi Rajesh.

I'm puzzled by your code. What's in your @links array that
has a 'url' method?
And I don't know of a WWW::Mechanize::get method that takes
two parameters.
I have the latest WWW::Mechanize from CPAN. Are you doing something
inscrutably clever?

Anyway, the answer is to use the URI::URL module (already
'require'd by
WWW::Mechanize) to build the absolute URL from the href=
field of the anchors
like this:

use strict;
use warnings;

use WWW::Mechanize;

my $mech = new WWW::Mechanize;

$mech->get('http://search.cpan.org/');

foreach (@{$mech->links}) {
print URI::URL->new_abs($_->[0], $mech->base), "n";
}

I hope this helps.

Happy Christmas!

Rob



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




Dan Muey
QUOTE
"Dan" == Dan Muey <[Email Removed]> writes:

I want to be able to return a true or false value from a
function in a module and populate the $! variable with the
specific errors. Is this possible? Is there documentation on
how to do this? I can find docs on how to use $! but not how to
set it. Thanks for any help -Ken

Dan> Did anyone ever reply to this post?  I couldn't find it in
Dan> the archives and I thinnk it's a pretty good question.

Dan> For instance would it be 'safe' and 'proper', and 'ok',
Dan> etc... to do somethign like:

Dan> sub whatever { my $foo = shift; undef $!; if($foo eq 'bar') {
Dan> return 1; } else { $! = "Foo must equal bar";return 0; } }

$! is for system-call-related errors that can be mapped to
errno return values.  I don't see "Foo must equal bar" fits
that definition. Perhaps you want to look at the "Exception" module.

Having said that, you can set $! to a numeric value, and
it'll return that number in a numeric context, and the
appropriate error text in a string context.  Rememeber that
$! is just a thin wrapper over errno though, so any
system-call-related activity will change it.

--
Thanks for the info, very helpful!


I know that RH 9 has major problems running TK. Something to do with the
way the lib's where linked. Try a google search for more info.

HTH..

Denis

On Wed, 31 Dec 2003, awongxi wrote:

QUOTE
I am running linux redhat ver 8. perl v5.8.0. I downloaded perltk from:
http://xbeams.chem.yale.edu/~loria/perltk.html and rpm it. I then tried
to run the example script from http://www.pconline.com/~erc/perltk.htm
but I am getting this error msg:

Can't locate auto/Tk/findINC.al in @INC (@INC contains:
/usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at
/usr/lib/perl5/5.8.0/Tk.pm line 51
Compilation failed in require at tkmenu.pl line 5.
BEGIN failed--compilation aborted at tkmenu.pl line 5.

I guess it has to do with the creation of the dinamic loadable
libraries... but I am not sure, and I do not knwo how to get this to
work, if some one could please tell me what am I doing wrong? how to
correct it.. cheers.


zentara wrote:

On Fri, 9 May 2003 10:13:16 +0200 , [Email Removed] (Ruben
Montes) wrote:



HI,
I want to write a simple script to generate a pop-up window that should
beclicked to get it closed... Where should I start?
Thanks,



Here's a start:
##################################################################
#!/usr/bin/perl
# test prg for notification window
use Tk;
use strict;

my $mw_bdw = 2;  #mainwindow border width
### Create a Mainwindow ###
my $main = new MainWindow(-borderwidth=>$mw_bdw,
-relief=>'ridge',
-bg => "#0000FF");

$main->geometry("150x100+0+0"); # displaying at top left on any
resolution
$main->overrideredirect(1); # Remove window decorations and keep on all
screens
### create a text widget ###
my $imstr = "THIS IS A TEST NOTIFICTION LONG ENOUGH TO WRAP";
my $TEXT = $main->Text(
-foreground=> 'white',
-background=> '#0000FF',
-wrap => 'word',
-height => 7,
-width => 50)->pack;

$TEXT->insert('end', "$imstr", );

#$main-> after(5000, &exitprg); # autoclose in 5000 milisecs
$main->bind('<ButtonRelease>',sub{$main->destroy}); #or sub exitprg

MainLoop;

#### FUNCTIONS ####
sub exitprg {
print STDERR "CALLED EXITn";
$main-> destroy; # to kill the window and exit from prog
}










Unknown Sender
I am running linux redhat ver 8. perl v5.8.0. I downloaded perltk from:
http://xbeams.chem.yale.edu/~loria/perltk.html and rpm it. I then tried
to run the example script from http://www.pconline.com/~erc/perltk.htm
but I am getting this error msg:

Can't locate auto/Tk/findINC.al in @INC (@INC contains:
/usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at
/usr/lib/perl5/5.8.0/Tk.pm line 51
Compilation failed in require at tkmenu.pl line 5.
BEGIN failed--compilation aborted at tkmenu.pl line 5.

I guess it has to do with the creation of the dinamic loadable
libraries... but I am not sure, and I do not knwo how to get this to
work, if some one could please tell me what am I doing wrong? how to
correct it.. cheers.


zentara wrote:

QUOTE
On Fri, 9 May 2003 10:13:16 +0200 , [Email Removed] (Ruben
Montes) wrote:



HI,
I want to write a simple script to generate a pop-up window that should
beclicked to get it closed... Where should I start?
Thanks,



Here's a start:
##################################################################
#!/usr/bin/perl
# test prg for notification window
use Tk;
use strict;

my $mw_bdw = 2;  #mainwindow border width
### Create a Mainwindow ###
my $main = new MainWindow(-borderwidth=>$mw_bdw,
-relief=>'ridge',
-bg => "#0000FF");

$main->geometry("150x100+0+0"); # displaying at top left on any
resolution
$main->overrideredirect(1); # Remove window decorations and keep on all
screens
### create a text widget ###
my $imstr = "THIS IS A TEST NOTIFICTION LONG ENOUGH TO WRAP";
my $TEXT = $main->Text(
-foreground=> 'white',
-background=> '#0000FF',
-wrap => 'word',
-height => 7,
-width => 50)->pack;

$TEXT->insert('end', "$imstr", );

#$main-> after(5000, &exitprg); # autoclose in 5000 milisecs
$main->bind('<ButtonRelease>',sub{$main->destroy}); #or sub exitprg

MainLoop;

#### FUNCTIONS ####
sub exitprg {
print STDERR "CALLED EXITn";
$main-> destroy; # to kill the window and exit from prog
}








Mike Bernhardt
I have a Sun Enterprise running Solaris 2.9. I installed Perl 5.8. I am now
trying to compile Math-GMP-2.03 and I get the following output on "make":
cp lib/Math/GMP.pm blib/lib/Math/GMP.pm
AutoSplitting blib/lib/Math/GMP.pm (blib/lib/auto/Math/GMP)
/usr/local/bin/perl /usr/local/lib/perl5/5.8.0/ExtUtils/xsubpp -typemap
/usr/local/lib/perl5/5.8.0/ExtUtils/typemap -typemap typemap GMP.xs >
GMP.xsc && mv GMP.xsc GMP.c
gcc -B/usr/ccs/bin/ -c -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_O
FFSET_BITS=64 -O -DVERSION="2.03" -DXS_VERSION="2.03" -fPIC
"-I/usr/local/lib/perl5/5.8.0/sun4-solaris/CORE" GMP.c
Running Mkbootstrap for Math::GMP ()
chmod 644 GMP.bs
rm -f blib/arch/auto/Math/GMP/GMP.so
LD_RUN_PATH="/usr/local/lib" gcc -B/usr/ccs/bin/ -G -L/usr/local/lib
MP.o -o blib/arch/auto/Math/GMP/GMP.so -lgmp
ld: fatal: file /usr/local/lib/libgmp.so: wrong ELF class: ELFCLASS64
ld: fatal: File processing errors. No output written to
blib/arch/auto/Math/GMP/GMP.so
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target
`blib/arch/auto/Math/GMP/GMP.so'


I did successfully install gmp-4.1.2, although maybe I need to specify some
options I don't understand? What the heck is ELF and ELFCLASS64, and what do
I do about them? I can't figure out what the problem is. The same problem
occurs with less info, using MCPAN.

Thanks for any help!

Drieux
On Dec 30, 2003, at 4:53 PM, Mike Bernhardt wrote:
[..]
QUOTE
ELF and ELFCLASS64,
[..]


ELF _ Executable and Linkable Format
<http://dict.die.net/elf/>

It appears that your library that you are trying to
link to was build with solaris64, and you are trying
to build in the 32 bit mode - they all need to be
one or the other...

cf:
<http://www.nntp.perl.org/group/perl.64bit/34>



ciao
drieux

---

R. Joseph Newton
Dan Muey wrote:

QUOTE
I want to be able to return a true or false value from a
function in a module and populate the $! variable with the
specific errors. Is this possible? Is there documentation on
how to do this? I can find docs on how to use $! but not how
to set it. Thanks for any help -Ken

Did anyone ever reply to this post?

Yes. There was actually an extensive thread.

QUOTE

I couldn't find it in the archives and I thinnk it's a pretty good question.

For instance would it be 'safe' and 'proper', and 'ok', etc... to do somethign like:

sub whatever {
my $foo = shift;
undef $!;
if($foo eq 'bar') { return 1; }
else { $! = "Foo must equal bar";return 0; }
}

TIA

Dan

I agree that a close localization can be relatively harmless, maybe even useful. Still
I would not recommend getting into the habit, since it could mask much more valuable
information from the interpreter, and since there are tons of other ways to communicate
custom errors.

Joseph

William Martell
Hi Zary,

I have attached a sample file with the data you offered and a perl script
which can be copied and pasted into the command line on win32.

Let me know if you have any problems.

HTH,
Will Martell
Dallas Texas

Jim Halkyard
Hi Will,

Just a couple of comments on the script you sent.

This is your script with some minor changes.

$infile = "zary_necheva_data.txt";

open(INFILE, $infile) or die "Death $!";

while( $line = <INFILE> ){

$lpos = index($line,"|");

# Your line will capture the first five chars, but in the sample data 2 of
the rows had 6 chars before the first . or space and were truncated
#$first = substr($line, 0, 5); # Will's line

# I suggest using the value of $lpos you captured above
$first = substr($line, 0, $lpos); # My line

# This will replace one or more dots with nothing within the substring, not
quite what was requested
#$first =~ s/.+//; # Will's line

# This will replace everything after the first dot or space in the substring
with nothing
$first =~ s/[.s].*//; # My line

$last = substr($line, $lpos);

print $first.$last;

}


You can also replace the while loop with

while(<INFILE>)
s/^(.*?)[.s].*?(|.*)$/$1$2/;
print;
}


I am sure there are many other ways of doing this, many of them probably
shorter, quicker code, but both these appear to work exactly as requested.

Cheers,

Jim

-----Original Message-----
From: William Martell [mailto:[Email Removed]]
Sent: 31 December 2003 14:33
To: [Email Removed]; Zary Necheva
Subject: RE:: Help with extracting text


Hi Zary,

I have attached a sample file with the data you offered and a perl script
which can be copied and pasted into the command line on win32.

Let me know if you have any problems.

HTH,
Will Martell
Dallas Texas

Tom Kinzer
You could do it with a mathematical operation based on the ASCII value...course that's not a regex.


-Tom Kinzer


-----Original Message-----
From: Kevin Old <[Email Removed]>
Sent: Jan 2, 2004 8:26 AM
To: [Email Removed]
Subject: Convert letter to phone keypad equivalent

Hello everyone,

Here's a script I wrote to convert letters into their telephone keypad
equivalents....example....A-B to 2, D-F to 3, etc.

#!/usr/bin/perl

use warnings;
use strict;

my $cnum = 'SM1550';

$cnum =~ s/[A-C]/2/g;
$cnum =~ s/[D-F]/3/g;
$cnum =~ s/[G-I]/4/g;
$cnum =~ s/[J-L]/5/g;
$cnum =~ s/[M-O]/6/g;
$cnum =~ s/[P-S]/7/g;
$cnum =~ s/[T-V]/8/g;
$cnum =~ s/[W-Y]/9/g;

print "$cnumn"

This works like a charm, but I wondered if anyone knew of a way to
consolidate this into fewer regex's. Like my post earlier this week,
I'm not trying to be lazy, just trying to learn other ways of
programming/consolidating regexes.

Any help is appreciated,
Kevin
--
Kevin Old <[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>

James Edward Gray II
On Jan 2, 2004, at 1:51 PM, Tom Kinzer wrote:

QUOTE
You could do it with a mathematical operation based on the ASCII
value...course that's not a regex.

It could be a regex, with the /e modifier.

This was actually my first thought and I attempted to implement it.
However, if you're leaving Q and Z in there, as the posted code was,
it's pretty tricky. That's what made me choose the tr/// which is
probably a lot more efficient and is surely more straightforward
anyway.

James

On Jan 05 12:13, Ramprasad A Padmanabhan <[Email Removed]> wrote:
QUOTE


But why do you want to do it in perl ( why not rm  -f  $dir/* $dir/.* )
, If you are removing all the 4000 files everytime it might make sense
to remove the entire directory and recreate it.


Ram


That is what I thought initially, but I ran into "Argument list too long" errors, so I think there is a limit of the number of returns from a wildcard (to avoid overrunning? I guess). The idea of loading it all into an array and deleting it one at a time makes sense, but only half of the 4000 entries are being loaded into DIR. I can't just blow away and recreate the folder as it is shared via samba and netatalk, and the clients' mount mappings would break.

Charles

QUOTE
That looks very, very wrong. You're binding a scalar to
something other than a regular expression. Tell us what you
are attempting to do here.

HTH,

Charles K. Clarkson

yeah, I agree. Here is the scenario:

I have a Mac client that is grabbing pictures and writing them to a netatalk share, and the files prefix with klee and then are one-up serialized (not my design, I just do networking). The PC client grabs the images via samba share and displays them. This is part of an museum exhibit (http://nano.arts.ucla.edu) that runs till September 2004. On a busy day, the system grabs around 4000 images.

We are archiving the pictures, so I have a cron script that copies the directory, tars the copy and sends it to a backup server. That all works, but I need to empty the source and copy directories. Previously, I was just calling rm -rf /test/directory/*, but I get "Argument too long" errors. So, I need to load the directory listing into an array, and rm or unlink them one at a time. When I use readdir(DIR, $testdir), I only get half of the entries. I tried explicitly declaring DIR as an array, but I guess handles don't do that. How do I load all of the directory into an array, or more specifically why am I only getting half? I'm using Perl 5.8 on Mac OSX Panther.

Thanks for the help,

Charles

James Edward Gray II
On Jan 5, 2004, at 2:23 AM, [Email Removed] wrote:

QUOTE
I tried explicitly declaring DIR as an array, but I guess handles
don't do that.  How do I load all of the directory into an array, or
more specifically why am I only getting half?

#!/usr/bin/perl

use strict;
use warnings;

my $dir = shift; # call with script_name directory_to_clear

opendir DIR, $dir or die "Directory error: $!";
my @files = grep /^klee/, readdir DIR; # load @files
closedir DIR;

# uncomment the following line if you would like a print out of how
many files we found
# print "Files found: ", scalar(@files), "n";
# uncomment the following line if you would like to see all files found
# print "$_n" foreach @files;

print "Files deleted: ", unlink(map { "$dir/$_" } @files), "n";

__END__

Hope the helps.

James

Atul Vohra
Hi,

Found out that the PATH size was smaller when running
from the web (IIS) compared to the command prompt.
Obviously, the most important path reqd for the C code
was at the end.

Thanks for everyone's input.

Atul

Dan Muey
QUOTE
I keep feeling I should learn more before I post here (lest I
look like a lazy
idiot who can't RTFM), but I'm getting too old to wait!
Anyway, first post:
Surely there's a module (or many) with a method to parse
URL's down to TLD. I
just can't find nice lists of them. I need to see if some
files came from the
same host. Here's what I'm doing now (just to show I'm
writing _some_ code):

my $link = $result->{URL};
my $slink = substr($link, 10, 7);
if($slink eq $temp){
...do stuff...
$temp=$slink
}

No. Look away. It's hideous.

I have a module I'm putting on cpan soon that has a grabdomain function.
Part of the trouble is the country part, to illustrate:
domain.com and domain.com.uk are both the "main domain". so my function takes
into account those and lets you add and remove which far right w+ would be two or three sections.
Then each section has to be properly formatted also. RFC can get sticky!

Keep your eye out on cpan for the SimpleMood module. It will have
lots of handy things to simplyify development.

QUOTE
(But it usually works).
OK, obviously I haven't gotten regexes down (or gotten to
their chapter at
all). My question is: how can I find (not just this but any) methods
available on cpan? Must I muck through google every time I want to
"q=learn+some+new+damn+perl&btnG=Google+Search"? It's such a
wasteland of
usenet postings from 1995!

http://search.cpan.org
perldoc -h

HTH

Dmuey
>

Anthony Esposito
Errata: The "last" print statement in the 'while' loop is the focus......

Tony Esposito
Oracle Developer, Enterprise Business Intelligence
XO Communications
Plano, TX 75074
Work Phone:
Work Cell:
Email: [Email Removed]


-----Original Message-----
From: Esposito, Anthony
Sent: Tuesday, January 06, 2004 2:54 PM
To: [Email Removed]
Subject: 'print' output on one line

I have a perl program ( with DBI ) which prints out a line to STDOUT
after every 100 database commits. I would like the 'print' to just
refresh the current line every time but - not knowing how to get around
it - the program instead prints a new line every 100 commits like so:



INFO 3: start deleting rows.

Rows deleted: 100

Rows deleted: 200

Rows deleted: 300

Rows deleted: 400

..

..

..

INFO 4: delete_rows.pl program ended.



I would like the output to just stay on one line and just update the
count as the program proceeds. So the output - when done - would just
be



INFO 3: start deleting rows.

Rows deleted: 400

INFO 4: delete_rows.pl program ended.



Is there a 'print' option/escape character the sends the file pointer (
for STDOUT in this case ) back to the beginning of the line?



Here is the current code segment - the focus here is on the last 'print'
statement:



print "INFO 3: start deleting rows.n";

while(($row_data) = $sth1->fetchrow) {

if(! defined ($sth2->execute($row_data))) { # execute DELETE

print "ERROR 4: execute of DELETE statement failed.n";

exit(int 4);

}

$row_counter = $row_counter + 1;

if($row_counter >= 100) {

$dbh->commit;

$rows_deleted = $rows_deleted + $row_counter;

print "Rows deleted: $rows_deletedn";

$row_counter = 0;

}

}

print "INFO 4: $0 program ended.n";



Thanks for any help you can offer....



Tony Esposito

Oracle Developer, Enterprise Business Intelligence

XO Communications

Plano, TX 75074

Work Phone:

Work Cell:

Email: [Email Removed]

Anthony Esposito
I tried that already but it just gives me the final count at the end. I would like the output to change - the row count, that is - as each 100 rows is committed with the final output - when the program ends - to be:

INFO 3: start deleting rows.

Rows deleted: 400

INFO 4: delete_rows.pl program ended.

In other words, as time goes by, you see on your screen:

INFO 3: start deleting rows.

Rows deleted: 100

then ( overwriting the above )

INFO 3: start deleting rows.

Rows deleted: 200

and so on until the end...

Tony Esposito
Oracle Developer, Enterprise Business Intelligence
XO Communications
Plano, TX 75074
Work Phone:
Work Cell:
Email: [Email Removed]


-----Original Message-----
From: Jenda Krynicky [mailto:[Email Removed]]
Sent: Tuesday, January 06, 2004 2:59 PM
To: [Email Removed]
Subject: Re: 'print' output on one line

From: "Esposito, Anthony" <[Email Removed]>
QUOTE
I have a perl program ( with DBI ) which prints out a line to STDOUT
after every 100 database commits.  I would like the 'print' to just
refresh the current line every time but - not knowing how to get
around it - the program instead prints a new line every 100 commits
like so:

INFO 3: start deleting rows.
Rows deleted: 100
Rows deleted: 200
Rows deleted: 300
Rows deleted: 400
...
print "Rows deleted: $rows_deletedn";

Use r instead of n:

print "Rows deleted: $rows_deletedr";

QUOTE

$row_counter = 0;

}

}

print "INFO 4: $0 program ended.n";

and don't forget to add a n in front of the "INFO 4..."

HTH, 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


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

Anthony Esposito
Alright, gents, you and I were both right......."r" works, as it should.
It turns out that these computers today - and Perl - are even faster than I thought.
My test data set was only 300 rows so by the time the program ran - and deleted - 300 rows the Perl program had only enough time to print the output once, making it 'appear' to not work. I had a suspicion that that may be the problem so I increased my test data set to 6000 and it worked fine.
Thanks all!

Close this thread.....

:-)

Tony Esposito
Oracle Developer, Enterprise Business Intelligence
XO Communications
Plano, TX 75074
Work Phone:
Work Cell:
Email: [Email Removed]


-----Original Message-----
From: Esposito, Anthony
Sent: Tuesday, January 06, 2004 3:09 PM
To: Jenda Krynicky; [Email Removed]
Subject: RE: 'print' output on one line

I tried that already but it just gives me the final count at the end. I would like the output to change - the row count, that is - as each 100 rows is committed with the final output - when the program ends - to be:

INFO 3: start deleting rows.

Rows deleted: 400

INFO 4: delete_rows.pl program ended.

In other words, as time goes by, you see on your screen:

INFO 3: start deleting rows.

Rows deleted: 100

then ( overwriting the above )

INFO 3: start deleting rows.

Rows deleted: 200

and so on until the end...

Tony Esposito
Oracle Developer, Enterprise Business Intelligence
XO Communications
Plano, TX 75074
Work Phone:
Work Cell:
Email: [Email Removed]


-----Original Message-----
From: Jenda Krynicky [mailto:[Email Removed]]
Sent: Tuesday, January 06, 2004 2:59 PM
To: [Email Removed]
Subject: Re: 'print' output on one line

From: "Esposito, Anthony" <[Email Removed]>
QUOTE
I have a perl program ( with DBI ) which prints out a line to STDOUT
after every 100 database commits.  I would like the 'print' to just
refresh the current line every time but - not knowing how to get
around it - the program instead prints a new line every 100 commits
like so:

INFO 3: start deleting rows.
Rows deleted: 100
Rows deleted: 200
Rows deleted: 300
Rows deleted: 400
...
print "Rows deleted: $rows_deletedn";

Use r instead of n:

print "Rows deleted: $rows_deletedr";

QUOTE

$row_counter = 0;

}

}

print "INFO 4: $0 program ended.n";

and don't forget to add a n in front of the "INFO 4..."

HTH, 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


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



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

R. Joseph Newton
"Esposito, Anthony" wrote:

QUOTE
I tried that already but it just gives me the final count at the end.  I would like the output to change - the row count, that is - as each 100 rows is committed with the final output - when the program ends - to be:

Try turning autoflush on:

Greetings! C:>perl -w
{
local $| = 1;
print "Hello, therer";
sleep 2;
print "Well, bye for nowr";
sleep 2;
}

^Z
Hello, there

[two seconds later...]
Greetings! C:>perl -w
{
local $| = 1;
print "Hello, therer";
sleep 2;
print "Well, bye for nowr";
sleep 2;
}

^Z
Well, bye for now

HTH,

Joseph

Anthony Esposito
Very helpful...thank you....

Tony Esposito
Oracle Developer, Enterprise Business Intelligence
XO Communications
Plano, TX 75074
Work Phone:
Work Cell:
Email: [Email Removed]


-----Original Message-----
From: R. Joseph Newton [mailto:[Email Removed]]
Sent: Tuesday, January 06, 2004 5:07 PM
To: Esposito, Anthony
Cc: Jenda Krynicky; [Email Removed]
Subject: Re: 'print' output on one line

"Esposito, Anthony" wrote:

QUOTE
I tried that already but it just gives me the final count at the end.  I would like the output to change - the row count, that is - as each 100 rows is committed with the final output - when the program ends - to be:

Try turning autoflush on:

Greetings! C:>perl -w
{
local $| = 1;
print "Hello, therer";
sleep 2;
print "Well, bye for nowr";
sleep 2;
}

^Z
Hello, there

[two seconds later...]
Greetings! C:>perl -w
{
local $| = 1;
print "Hello, therer";
sleep 2;
print "Well, bye for nowr";
sleep 2;
}

^Z
Well, bye for now

HTH,

Joseph


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.