Re: newbie question for parsing incoming mails

2017-02-16 Thread Jim Gibson

> On Feb 15, 2017, at 9:56 PM, Eko Budiharto  wrote:
> 
> Jim,
> I have one a couple more questions.
> -. For the header, what if, I just need the subject, the from, and the 
> recipient, what is the command? I read the manual in the 
> https://metacpan.org/pod/Email::MIME#header, it does not tell me how to 
> extract all of those.
> -. And then, for the email contents of the body, it just shows Content-Type: 
> multipart/alternative; boundary=f403045de9521d20cc054874ce1a 
> instead of the contents of the email body. How to extract it into string 
> because it is under html format.

Please post all questions to the list. There are other people who can answer 
your questions better than I can.

I just parse the text of the email using regular expressions, line by line:

my @lines = split(/[\n\r]+/,$text);

for( my $i = 0; $i <= $#lines; $i++ ) {
my $line = $lines[$i];
print "$i. $line\n" if $xdebug;

if( $line =~ m{ \A Subject:\ (.*) \z }x ) {
$subject = $1;

etc.

You can also try to use the Email::MIME::header method:

my $from = $mime->header(‘From’):

I haven’t used that, but it might be worth trying. Email::MIME is an extension 
of the Email::Simple class, so you can look at the documentation for that 
module as well. 
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question for parsing incoming mails

2017-02-15 Thread Eko Budiharto
dear all,
I have one a couple questions.
-. For the header, what if, I just need the subject, the from, and the 
recipient, what is the command? I read the manual in the 
https://metacpan.org/pod/Email::MIME#header 
, it does not tell me how to 
extract all of those.
-. And then, for the email contents of the body, it just shows Content-Type: 
multipart/alternative; boundary=f403045de9521d20cc054874ce1a 
instead of the contents of the email body. How to extract it into string 
because it is under html format.

> On Feb 16, 2017, at 11:45, Jim Gibson  wrote:
> 
> 
>> On Feb 15, 2017, at 8:10 PM, Eko Budiharto  wrote:
>> 
>> dear Jim,
>> I tried to add lines to read file like this:
>> 
>> use Email::MIME;
>> 
>> my $file = '/var/qmail/mailnames/> name>/support/Maildir/cur/1487041394.M984019P23084V0803I00E03878.ABCD.NET,S=3987:2,';
>> open my $ifh, '<', $file
>>  or die "Cannot open '$file' for reading: $!";
>> local $/ = '';
>> my $contents = <$ifh>;
>> close( $ifh );
>> 
>> my $mime = Email::MIME->($contents);  —> line 13
>> 
>> my @parts = $mime->parts();
>> 
>> for my $npart ( 0..$#parts ) {
>>  my $part = $parts[$npart];
>>  my $header = $part->header_obj();
>>  my $htext = $header->as_string();
>>  my $body = $part->body();
>> 
>>  print $header;
>> }
>> 
>> after I ran its from CLI, I got an error message Undefined subroutine 
>> &Email::MIME called at line 13.
>> 
>> what does the error mean?
> 
> That means I mistyped the line. It should be this:
> 
>   my $mime = Email::MIME->new($contents);
> 
> 



Re: newbie question for parsing incoming mails

2017-02-15 Thread Jim Gibson
On Feb 15, 2017, at 7:10 PM, Eko Budiharto  wrote:
> 
> Jim, 
> if I want to extract all incoming emails from my qmail emails, how can 
> specify the folder location and specify the file name since the file name 
> always different?
> 
> Thx.

Use File::Find or opendir and readdir to find all of the emails in a directory 
tree. You need to figure out the parent directory, if there is one, of the 
local storage for your email client.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question for parsing incoming mails

2017-02-15 Thread Jim Gibson

> On Feb 15, 2017, at 8:10 PM, Eko Budiharto  wrote:
> 
> dear Jim,
> I tried to add lines to read file like this:
> 
> use Email::MIME;
> 
> my $file = '/var/qmail/mailnames/ name>/support/Maildir/cur/1487041394.M984019P23084V0803I00E03878.ABCD.NET,S=3987:2,';
> open my $ifh, '<', $file
>   or die "Cannot open '$file' for reading: $!";
> local $/ = '';
> my $contents = <$ifh>;
> close( $ifh );
> 
> my $mime = Email::MIME->($contents);  —> line 13
> 
> my @parts = $mime->parts();
> 
> for my $npart ( 0..$#parts ) {
>   my $part = $parts[$npart];
>   my $header = $part->header_obj();
>   my $htext = $header->as_string();
>   my $body = $part->body();
> 
>   print $header;
> }
> 
> after I ran its from CLI, I got an error message Undefined subroutine 
> &Email::MIME called at line 13.
> 
> what does the error mean?

That means I mistyped the line. It should be this:

my $mime = Email::MIME->new($contents);

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question for parsing incoming mails

2017-02-15 Thread Eko Budiharto
dear Jim,
I tried to add lines to read file like this:

use Email::MIME;

my $file = '/var/qmail/mailnames//support/Maildir/cur/1487041394.M984019P23084V0803I00E03878.ABCD.NET,S=3987:2,';
open my $ifh, '<', $file
  or die "Cannot open '$file' for reading: $!";
local $/ = '';
my $contents = <$ifh>;
close( $ifh );

my $mime = Email::MIME->($contents);  —> line 13

my @parts = $mime->parts();

for my $npart ( 0..$#parts ) {
  my $part = $parts[$npart];
  my $header = $part->header_obj();
  my $htext = $header->as_string();
  my $body = $part->body();

  print $header;
}

after I ran its from CLI, I got an error message Undefined subroutine 
&Email::MIME called at line 13.

what does the error mean?



> On Feb 15, 2017, at 22:56, Jim Gibson  wrote:
> 
> I use Email::MIME to parse email messages. After reading the email file into 
> the variable $text I do this:
> 
> my $mime = Email::MIME->($text);
> my @parts = $mime->parts();
> 
> for my $npart ( 0..$#parts ) {
>  my $part = $parts[$npart];
>  my $header = $part->header_obj();
>  my $htext = $header->as_string();
>  my $body = $part->body();
>  …
> }
> 
> 
> 
> 
> 
> Jim Gibson



Re: newbie question for parsing incoming mails

2017-02-15 Thread Eko Budiharto
Jim, 
if I want to extract all incoming emails from my qmail emails, how can specify 
the folder location and specify the file name since the file name always 
different?

Thx.
> On Feb 15, 2017, at 22:56, Jim Gibson  wrote:
> 
>> 
>> On Feb 14, 2017, at 10:38 PM, Eko Budiharto  wrote:
>> 
>> dear all,
>> I have a question. 
>> If I would like to parse all incoming mails from my qmail, which perl module 
>> is easy to use?
>> my qmail emails incoming is /var/qmail/mailnames//support. In 
>> this folder I already have preline in .qmail for piping emails to my perl 
>> script.
>> And, my perl script what I already have is like this:
>> 
>> #!/usr/bin/perl -w
>> 
>> use Mail::Internet;
>> 
>> my $mail = Mail::Internet->new( [  ] );
>> my $headers = $mail->head->header_hashref;
>> my @subject = @{${$headers}{'Subject'}}; # or otherwsie do it in list 
>> context it works
>> 
>> print @subject;
>> 
>> 
>> when I run it, I do not get anything.
>> 
>> please help.
> 
> I use Email::MIME to parse email messages. After reading the email file into 
> the variable $text I do this:
> 
> my $mime = Email::MIME->($text);
> my @parts = $mime->parts();
> 
> for my $npart ( 0..$#parts ) {
>  my $part = $parts[$npart];
>  my $header = $part->header_obj();
>  my $htext = $header->as_string();
>  my $body = $part->body();
>  …
> }
> 
> 
> 
> 
> 
> Jim Gibson



Re: newbie question for parsing incoming mails

2017-02-15 Thread Andy Bach
> when I run it, I do not get anything.
Hmm, how are you testing it. I put a single header and msg in /tmp/ml.txt
(Subject: training.error Trouble wiwb) and:
$ parse_email_simple.pl < /tmp/ml.txt
training.error Trouble wiwb (8 lines)
$ cat /tmp/ml.txt | parse_email_simple.pl
training.error Trouble wiwb (8 lines)

In addition, if I take out STDOUT
my $mail = Mail::Internet->new( [ <> ] );

I can do:
$ parse_email_simple.pl  /tmp/ml.txt

as Perl'll open the command line file name argument

Note, these'll treat all input as a single msg.

On Wed, Feb 15, 2017 at 12:38 AM, Eko Budiharto 
wrote:

> dear all,
> I have a question.
> If I would like to parse all incoming mails from my qmail, which perl
> module is easy to use?
> my qmail emails incoming is /var/qmail/mailnames//support.
> In this folder I already have preline in .qmail for piping emails to my
> perl script.
> And, my perl script what I already have is like this:
>
> #!/usr/bin/perl -w
>
> use Mail::Internet;
>
> my $mail = Mail::Internet->new( [  ] );
> my $headers = $mail->head->header_hashref;
> my @subject = @{${$headers}{'Subject'}}; # or otherwsie do it in list
> context it works
>
> print @subject;
>
>
> when I run it, I do not get anything.
>
> please help.
>
> regards,
> Eko
>



-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk


Re: newbie question for parsing incoming mails

2017-02-15 Thread Jim Gibson

> On Feb 14, 2017, at 10:38 PM, Eko Budiharto  wrote:
> 
> dear all,
> I have a question. 
> If I would like to parse all incoming mails from my qmail, which perl module 
> is easy to use?
> my qmail emails incoming is /var/qmail/mailnames//support. In 
> this folder I already have preline in .qmail for piping emails to my perl 
> script.
> And, my perl script what I already have is like this:
>  
> #!/usr/bin/perl -w
>  
> use Mail::Internet;
> 
> my $mail = Mail::Internet->new( [  ] );
> my $headers = $mail->head->header_hashref;
> my @subject = @{${$headers}{'Subject'}}; # or otherwsie do it in list context 
> it works
> 
> print @subject;
> 
> 
> when I run it, I do not get anything.
> 
> please help.

I use Email::MIME to parse email messages. After reading the email file into 
the variable $text I do this:

my $mime = Email::MIME->($text);
my @parts = $mime->parts();

for my $npart ( 0..$#parts ) {
  my $part = $parts[$npart];
  my $header = $part->header_obj();
  my $htext = $header->as_string();
  my $body = $part->body();
  …
}





Jim Gibson

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question : about the perl sprintf

2009-10-25 Thread Dr.Ruud

Majian wrote:

I found these :
perl -e'print 01.234 + 01.234', "\n"'
perl -e'print 01.234 + 011.234' "\n"'
perl -e'print 01.234.12 + 01.234', "\n"'

And the results were :

1235234
1235234
1235.12234


For other surprises, try also:

perl -wle 'print length(01.234.12)'
perl -wle 'print 01.234.12'

perl -wle 'print length(1.234.12)'
perl -wle 'print length(0+1.234.12)'

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question : about the perl sprintf

2009-10-25 Thread Philip Potter
2009/10/25 Majian :
> I found these :
> perl -e'print 01.234 + 01.234', "\n"'

print (01).(234+01).234, "\n";

this evaluates to '1'.'235'.'234'

> perl -e'print 01.234 + 011.234' "\n"'

I didn't get 1235234, I got 1243234.
print (01).(234+011).(234),"\n"
evaluates to
print '1'.(234+9).'234',"\n";
evaluates to
print '1'.'243'.'234',"\n";

> perl -e'print 01.234.12 + 01.234', "\n"'

I'll let you work this one out as an exercise. The key point is that
you can't have decimal octal numbers, so the . operator is interpreted
as the string concatenation operator.

Phil

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question : about the perl sprintf

2009-10-25 Thread Majian
I found these :
perl -e'print 01.234 + 01.234', "\n"'
perl -e'print 01.234 + 011.234' "\n"'
perl -e'print 01.234.12 + 01.234', "\n"'

And the results were :

1235234
1235234
1235.12234



Can someone explain it ?

Thanks~~


On Sat, Oct 24, 2009 at 7:28 PM, Peter Scott  wrote:

> On Wed, 21 Oct 2009 20:52:05 +0800, Majian wrote:
> > And  I modify it like this "sprintf "The number in
> > scientific
> > notation is %e", 01.255;"
> > The screen now output is " The number in scientific
> > notation
> > is 1.255000e+03"
>
> Ha, this is an interesting case.  By putting the zero before the 1, it
> turns it into an octal number and now the period becomes the concatenation
> operator instead of a decimal point, yielding a term of 1255.
>
> Try printf "The number in scientific notation is %e", 037.255"; and see
> what happens.
>
> --
> Peter Scott
> http://www.perlmedic.com/
> http://www.perldebugged.com/
> http://www.informit.com/store/product.aspx?isbn=0137001274
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: newbie question : about the perl sprintf

2009-10-24 Thread Peter Scott
On Wed, 21 Oct 2009 20:52:05 +0800, Majian wrote:
> And  I modify it like this "sprintf "The number in
> scientific
> notation is %e", 01.255;"
> The screen now output is " The number in scientific
> notation
> is 1.255000e+03"

Ha, this is an interesting case.  By putting the zero before the 1, it 
turns it into an octal number and now the period becomes the concatenation 
operator instead of a decimal point, yielding a term of 1255.

Try printf "The number in scientific notation is %e", 037.255"; and see 
what happens.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question : about the perl sprintf

2009-10-22 Thread uap12
On 21 Okt, 14:52, jian...@gmail.com (Majian) wrote:
> Hi, all ;
>
>            I want to print  this sentence " The number in scientific
> notation is 1.255000e+02".
>
>          So   I write a perl script like this :
>                #!/usr/bin/perl
>                 sprintf "The number in scientific notation is %e", 1.255;
>            But  the screen output is "The number in scientific notation is
> 1.255000e+00"
>
>             And  I modify it like this "sprintf "The number in scientific
> notation is %e", 01.255;"
>                 The screen now output is " The number in scientific notation
> is 1.255000e+03"
>
>            I don't know how I can display the correct answer .
>
>       Please forgive me if this is a very simple question on Perl . I am a
> Perl newbie ~~~
>
>           Thanks ~~~

#!/usr/bin/perl
printf("The number in scientific notation is %e\n", 125.55);
Gives The number in scientific notation is 1.255500e+002

I test to enter the result you are looking for as

perl -42 de  now ju can test single line of Perl kode

heter i enter print 1.255500e+02

( CTRL-Z) takes you out, (att least in WIndows version of PERL)

You can read more about formating data in this link
http://perldoc.perl.org/functions/sprintf.html

Best regards
Anders


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question : about the perl sprintf

2009-10-21 Thread Christian Bernini
>
> sprintf "The number in scientific notation is %e", 1.255;
>

Sprintf doesn't print actually, it just returns a string based on the
formats provided in the list you have.

To actually print something you should use printf.

printf "The number in scientific notation is %e",1255;


And the notation 1.255000e+03 is right as the output since it means 1.255000
* (10^3), so

1.255 * 1000 = 1255.

(as Jim already said)

Att.
Christian Bernini


Re: newbie question : about the perl sprintf

2009-10-21 Thread Jim Gibson

At 8:52 PM +0800 10/21/09, Majian wrote:

Hi, all ;

   I want to print  this sentence " The number in scientific
notation is 1.255000e+02".

 So   I write a perl script like this :
   #!/usr/bin/perl
sprintf "The number in scientific notation is %e", 1.255;
   But  the screen output is "The number in scientific notation is
1.255000e+00"


I don't get anything when I execute that line. You must have used the 
printf function in your actual code.


1.255000e+00 is the correct scientific representation of the number 
1.255. If you want to print 1.255000e+02, then you should print the 
number 125.5.



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Newbie question about variables, arrays and where they all go

2009-01-19 Thread Telemachus
On Mon Jan 19 2009 @  4:21, dolphin_sonar wrote:
> Again, you answered my question. You should be teaching Perl as your
> responses are very clear and that's not easy for people to do...give
> clear, concise responses.

Actually, I had a big goof in my response. The program and the print
statement are fine as you had them, and *I* got myself turned around.

When I typed up your program, I was thinking of other ways I might do it,
and I produced this:

sub running_sum {
state $sum = 0;
state @numbers;

push @numbers, @_;
$sum += $_ foreach @numbers;  ## WRONG - should be foreach @_
say "The sum of (@numbers) is $sum";
}

I thought it would be easier to push the whole @_ array into @numbers at
once and add everything into $sum in a one-liner as well. But I did it
wrong.

The problem was that I added the entire @numbers array to $sum, but from
from call to call, I only want to add the new items (the ones in the @_
array). That's what I get for trying to answer a question and rewrite the
example all at the same time.

As for 'say' it's a new feature in 5.10 (like the state variables) which
allows you to print without explicitly asking for the "\n" - it looks like
it's officially introduced in Learning Perl 5e on page 90.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Newbie question about variables, arrays and where they all go

2009-01-19 Thread dolphin_sonar
On Jan 18, 7:54 pm, telemac...@arpinum.org (Telemachus) wrote:
> On Sun Jan 18 2009 @ 10:59, dolphin_sonar wrote:
>
> >    1 # When calling 'running_sum(5, 6);' the variable 'state @numbers'
> > receives those two
> >    2 # parameters, (5 and 6), right? Then, the @numbers array also
> > copies/stores (5 and 6)
> >    3 # into the special '( @_ )' variable as well, right? Also, line
> > 13 pushes '$number' into
> >    4 # the '@numbers' array each time through the foreach loop,
> > right?
>
> Maybe I'm not understanding what you mean, but I think you're confused. The
> arguments to a subroutine go into the @_ array. The @numbers array is
> empty until you load it up in the foreach loop. Having 5 and 6 as arguments
> does not automatically put those items into @numbers, nor does @numbers
> copy anything into @_.
>
> Also, I understand that you may just be testing out persistent variables in
> 5.10, but this program is confusing.
>
> Consider what happens if you call running sum a second time (say as
> running_sum( 2, 7 );) If I add that call, here's my output:
>
>     telemachus ~ $ perl sum
>     The sum of (5 6) is 11
>     The sum of (5 6 2 7) is 31
>
> That appears to say that perl has added 5, 6, 2, and 7 up to 31. What
> actually happened was that you added 5, 6, 2 and 7 (20) to 11 (the sum from
> the previous call to running_sum - which was saved). To put this another way
> around: maybe you want to keep a running sum, but the print statement in the
> subroutine is very confusing.
>
> Hope this helps, T

T!

Again, you answered my question. You should be teaching Perl as your
responses are very clear and that's not easy for people to do...give
clear, concise responses.

Regardless, I now understand exactly what your saying about the state
@numbers declaration. I was confused about that and that helps me
understand a lot of what is going on, that was important for me to
understand. The example code actually had two more calls to running
sum: running_sum( 1..3 ); and running_sum( 4 ); (see the link to the
code and the out below).

Here is a link to the example code in a much better format, you can
see the code better than using Gmail IMO. http://sial.org/pbot/34575

# The output I get each time is this:
The sum of (5 6) is 11
The sum of (5 6 1 2 3 ) is 17
The sum of (5 6 1 2 3 4 ) is 21

This example comes from page 68 O'Reilly Learning Perl 5th edition.
They also used 'say' for the first time in the book instead of print
as well, which was kind of confusing to me.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Newbie question about variables, arrays and where they all go

2009-01-18 Thread Telemachus
From: Telemachus 
Date: Sun, 18 Jan 2009 20:17:27 -0500
To: beginners@perl.org
Subject: Re: Newbie question about variables, arrays and where they all go

On Sun Jan 18 2009 @  7:54, Telemachus wrote:
> The arguments to a subroutine go into the @_ array. The @numbers array is
> empty until you load it up in the foreach loop. 

Edit: I should have said that the @numbers array is empty before the *first*
run. Since it's persistent, after that it already contains all the items from
previous calls. So on a second call, it already has 5 and 6. (I should also
consider spelling 'understand' with a d.)

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Newbie question about variables, arrays and where they all go

2009-01-18 Thread Telemachus
On Sun Jan 18 2009 @ 10:59, dolphin_sonar wrote:
>1 # When calling 'running_sum(5, 6);' the variable 'state @numbers'
> receives those two
>2 # parameters, (5 and 6), right? Then, the @numbers array also
> copies/stores (5 and 6)
>3 # into the special '( @_ )' variable as well, right? Also, line
> 13 pushes '$number' into
>4 # the '@numbers' array each time through the foreach loop,
> right?

Maybe I'm not understaning what you mean, but I think you're confused. The
arguments to a subroutine go into the @_ array. The @numbers array is
empty until you load it up in the foreach loop. Having 5 and 6 as arguments
does not automatically put those items into @numbers, nor does @numbers
copy anything into @_.

Also, I understand that you may just be testing out persistent variables in
5.10, but this program is confusing.

Consider what happens if you call running sum a second time (say as
running_sum( 2, 7 );) If I add that call, here's my output:

telemachus ~ $ perl sum
The sum of (5 6) is 11
The sum of (5 6 2 7) is 31

That appears to say that perl has added 5, 6, 2, and 7 up to 31. What
actually happened was that you added 5, 6, 2 and 7 (20) to 11 (the sum from
the previous call to running_sum - which was saved). To put this another way
around: maybe you want to keep a running sum, but the print statement in the
subroutine is very confusing.

Hope this helps, T

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie question - handling email addresses

2008-05-14 Thread Munzilla
Great, thanks.  I had hoped that was the case.

On May 14, 11:33 am, [EMAIL PROTECTED] (Gunnar Hjalmarsson) wrote:
> Munzilla wrote:
> > i was told that Perl doesn't like the "@" character
>
> Then you were told wrong.
>
> What you need to take into account is that the '@' character in a double
> quoted string needs to be escaped, or else Perl tries to interpret it as
> the start of an array variable.
>
> As regards data from a form submission, the '@' character does not need
> any special treatment.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl


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




Re: newbie question - handling email addresses

2008-05-14 Thread Gunnar Hjalmarsson

Munzilla wrote:

i was told that Perl doesn't like the "@" character


Then you were told wrong.

What you need to take into account is that the '@' character in a double 
quoted string needs to be escaped, or else Perl tries to interpret it as 
the start of an array variable.


As regards data from a form submission, the '@' character does not need 
any special treatment.


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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




Re: Newbie question on substitution with Subroutines

2007-10-25 Thread Dr.Ruud
"minky arora" schreef:

> my ($count,$count1,$count3,$count2);

Consider: my @count;

-- 
Affijn, Ruud

"Gewoon is een tijger."

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




Re: Newbie question on substitution with Subroutines

2007-10-25 Thread Paul Lalli
On Oct 25, 12:01 pm, [EMAIL PROTECTED] (Minky Arora) wrote:
> I need to make multiple substitutions in a file.There could be a
> situation where there are more than one substitution on a single
> line.I want to count the total # of substituitions.I need to use
> subroutines:

Says who?  Is this a homework assignment?  If so why aren't you asking
your teacher for help?

> I have 3 questions:
>
> 1) Do I have to make 3 separate Regex.

It depends on what you are substituting and replacing.  If you're
searching for three different things and replacing them all with the
same thing, then no.  Just use the | alternation regexp character.

> How can it be done in a single line?

Why do you want it to be?

> 2)How to use Subroutines with this?  If I just want the Sub to
> substitute the value and return the line?

The same way you use subroutines in any other way.  What is your
question here?  Do you not know how to write a subroutine?  Do you not
know how to call a subroutine?

Have you read `perldoc perlsub` yet?

> 3)Is it a good practice to open the file using Sub? If so, how to do that?

This question is nonsensical.   Try again.

> !/usr/bin/perl -w

You forgot the # in front of the shebang.  This code does not compile.

> use strict;
> my $line;
> my ($count,$count1,$count3,$count2);
>
> open FILE, "data.txt" or die"cnt open $!";
>foreach $LINE() {

Don't use foreach() to process a file line-by-line.  Use while().


> if ($var =~ s/cellomics/array/g) {
> $count1++;
>   }

This counts the number of lines in which this substitution was made.
It does not count the number of substitutions that were made.  That
is, if this line contained two instances of cellomics that were both
replaced with array, $count1 would only go up by one, not by two.  If
that's what you want, fine.  If not, change to:

$count1 += ($var =~ s/cellomics/array/g);

>   if  ($var=~ s/perkin almer/janus/g) {
> $count2++
> }
>   if  ($var =~ s/dell/laptop/g)  {
> $count3++
> }}

Same comments here.

Paul Lalli


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




RE: Newbie Question

2006-09-20 Thread M K Scott
Thanks to all who replied - it is working fine now and I am now moving on to 
the next problemall your help was appreciated and very usefull.  I am sure 
I will be back here soon.
 
Thanks
Mark



From: John W. Krahn [mailto:[EMAIL PROTECTED]
Sent: Wed 20/09/2006 17:07
To: Perl Beginners
Subject: Re: Newbie Question



M K Scott wrote:
> Hi,

Hello,

> I have tried that to no avail.  I have also tried a simple match
> of !~ m/(m|f){1}/ and even put in the code you suggested to read
> !~ m/^(m|f){1}$/ but this still doesn't work properly.   Input of
> "d" or "T" will work to say it is incorrect and input of "m" or
> "f" will be accepted but I was under the impression that the {1}
> would limit it to only accept a single character while in practice
> it still accepts "ff" and "mmm".   Any ideas?

The expression above seems to work for me:

$ perl -le'
for ( qw/ a aa aaa f ff fff m mm mmm / ) {
print "$_: ", !/^(m|f){1}$/ ? "NOT " : "", "found";
}
'
a: NOT found
aa: NOT found
aaa: NOT found
f: found
ff: NOT found
fff: NOT found
m: found
mm: NOT found
mmm: NOT found

Note that /^(m|f){1}$/ could also be written as /^[mf]$/.


> One further question though, an example question I am doing asks
> for a text file to be read in and the number of digits to be
> counted (ie 3 "1"'s, 6 "2"'s etc) and I can read input in and do
> a 'getc' and pattern match that against a hash containing word
> references to the numbers and then add one to a count but is
> this the best way to do this?

Using getc() is usually not the best way to do anything in Perl.




John
--
use Perl;
program
fulfillment

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





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




Re: Newbie Question

2006-09-20 Thread John W. Krahn
M K Scott wrote:
> Hi,

Hello,

> I have tried that to no avail.  I have also tried a simple match
> of !~ m/(m|f){1}/ and even put in the code you suggested to read
> !~ m/^(m|f){1}$/ but this still doesn't work properly.   Input of
> "d" or "T" will work to say it is incorrect and input of "m" or
> "f" will be accepted but I was under the impression that the {1}
> would limit it to only accept a single character while in practice
> it still accepts "ff" and "mmm".   Any ideas?

The expression above seems to work for me:

$ perl -le'
for ( qw/ a aa aaa f ff fff m mm mmm / ) {
print "$_: ", !/^(m|f){1}$/ ? "NOT " : "", "found";
}
'
a: NOT found
aa: NOT found
aaa: NOT found
f: found
ff: NOT found
fff: NOT found
m: found
mm: NOT found
mmm: NOT found

Note that /^(m|f){1}$/ could also be written as /^[mf]$/.


> One further question though, an example question I am doing asks
> for a text file to be read in and the number of digits to be
> counted (ie 3 "1"'s, 6 "2"'s etc) and I can read input in and do
> a 'getc' and pattern match that against a hash containing word
> references to the numbers and then add one to a count but is
> this the best way to do this?

Using getc() is usually not the best way to do anything in Perl.




John
-- 
use Perl;
program
fulfillment

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




RE: Newbie Question

2006-09-20 Thread Lee Goddard
use strict;
use warnings;

my $string;
while (1){
print "Please enter 1-5 letters: ";
chomp ($string = );
last if $string =~ m/^[a-z]{1,5}$/i;
# last if $string =~ m/^\w{1,5}$/;
print "that is wrongtry again: ";
}

I think the problem was not the pattern so much as the rest of the
logic.

The pattern you have will match a lower- or upper-case letter of the
alphabet one or five times. I can't see how anchoring it to the start or
end of the $string would help anything other than perhaps internal
efficiency, for which I'd anchor it at both ends (^ and $ for start and
end). I would suggest using the /i modifier, so instead of /[a-zA-Z]/ to
match any letter, you could /[a-z]/i. 

But that's not really 'any letter' -- it's just a to z, which may ignore
accented and other UTF-8 characters. You can find better options in
perldoc perlre -- see esp. the POSIX section.

Your original code also seemed to be warning of an error before taking
input, but I guess that's a cut-n-paste issue.

Hth
lee

> From: M K Scott [mailto:[EMAIL PROTECTED] 
>
> I have tried that to no avail.  I have also tried a simple 
> match of !~ m/(m|f){1}/ and even put in the code you 
> suggested to read !~ m/^(m|f){1}$/ but this still doesn't 
> work properly.   Input of "d" or "T" will work to say it is 
> incorrect and input of "m" or "f" will be accepted but I was 
> under the impression that the {1} would limit it to only 
> accept a single character while in practice it still accepts 
> "ff" and "mmm".   Any ideas?
>  
> One further question though, an example question I am doing 
> asks for a text file to be read in and the number of digits 
> to be counted (ie 3 "1"'s, 6 "2"'s etc) and I can read input 
> in and do a 'getc' and pattern match that against a hash 
> containing word references to the numbers and then add one to 
> a count but is this the best way to do this?
>  
> Thanks again,
> Mark
> 
> 
> 
> From: John W. Krahn [mailto:[EMAIL PROTECTED]
> Sent: Wed 20/09/2006 01:12
> To: Perl Beginners
> Subject: Re: Newbie Question
> 
> 
> 
> M K Scott wrote:
> > Hi all,
> 
> Hello,
> 
> > Please forgive the newbie nature of this question but i'm just 
> > starting off teaching myself perl from scratch and so need a little 
> > clarification.
> > 
> > I am trying to put together a script to do pattern matching 
> and while 
> > I can get the basic syntax alright it doesn't seem to be working as
> > expected.   For one example I need to match a user input 
> and make sure
> > it is a certain length (i.e. doesn't exceed a certain number of
> > characters) and this is the code so far:
> > 
> > while ($string != m/[a-zA-Z]{1,5}/ )
> > { print("that is wrongtry again: ");
> >chomp ($string = );   }
> 
> You need to anchor the pattern like /^[a-zA-Z]{1,5}$/

-- 

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


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




RE: Newbie Question

2006-09-20 Thread M K Scott
Hi,
 
I have tried that to no avail.  I have also tried a simple match of !~ 
m/(m|f){1}/ and even put in the code you suggested to read !~ m/^(m|f){1}$/ but 
this still doesn't work properly.   Input of "d" or "T" will work to say it is 
incorrect and input of "m" or "f" will be accepted but I was under the 
impression that the {1} would limit it to only accept a single character while 
in practice it still accepts "ff" and "mmm".   Any ideas?
 
One further question though, an example question I am doing asks for a text 
file to be read in and the number of digits to be counted (ie 3 "1"'s, 6 "2"'s 
etc) and I can read input in and do a 'getc' and pattern match that against a 
hash containing word references to the numbers and then add one to a count but 
is this the best way to do this?
 
Thanks again,
Mark

____

From: John W. Krahn [mailto:[EMAIL PROTECTED]
Sent: Wed 20/09/2006 01:12
To: Perl Beginners
Subject: Re: Newbie Question



M K Scott wrote:
> Hi all,

Hello,

> Please forgive the newbie nature of this question but i'm just
> starting off teaching myself perl from scratch and so need a little
> clarification.
> 
> I am trying to put together a script to do pattern matching and while
> I can get the basic syntax alright it doesn't seem to be working as
> expected.   For one example I need to match a user input and make sure
> it is a certain length (i.e. doesn't exceed a certain number of
> characters) and this is the code so far:
> 
> while ($string != m/[a-zA-Z]{1,5}/ )
> { print("that is wrongtry again: ");
>chomp ($string = );   }

You need to anchor the pattern like /^[a-zA-Z]{1,5}$/


John
--
use Perl;
program
fulfillment

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





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




Re: Newbie Question

2006-09-19 Thread John W. Krahn
M K Scott wrote:
> Hi all,

Hello,

> Please forgive the newbie nature of this question but i'm just
> starting off teaching myself perl from scratch and so need a little
> clarification.
>  
> I am trying to put together a script to do pattern matching and while
> I can get the basic syntax alright it doesn't seem to be working as
> expected.   For one example I need to match a user input and make sure
> it is a certain length (i.e. doesn't exceed a certain number of
> characters) and this is the code so far:
>  
> while ($string != m/[a-zA-Z]{1,5}/ ) 
> { print("that is wrongtry again: "); 
>chomp ($string = );   }

You need to anchor the pattern like /^[a-zA-Z]{1,5}$/


John
-- 
use Perl;
program
fulfillment

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




Re: Newbie Question

2006-09-19 Thread Igor Sutton


while ($string != m/[a-zA-Z]{1,5}/ )
{ print("that is wrongtry again: ");
   chomp ($string = );   }



Maybe:

while ($string !~ m/.../) {
...
}

When you're matching against regular expressions, you need to use =~ or !~.

Hope this helps.

--
Igor Sutton Lopes
t: +55 51 9627.0779
e: [EMAIL PROTECTED]


Re: newbie question about regex

2004-09-03 Thread David Dorward
On Fri, Sep 03, 2004 at 04:33:43PM +0200, Maurice Lucas wrote:
> $ ./count.pl /var/log/file text
> this works fine but sometimes the "text" is "foo(bar)" and then my scripts 
> gives an error.
> syntax error near unexpected token `foo(b'

That's a shell issue, not a Perl issue. Escape your brackets or
quite your text so that bash (or sh or whatever) won't try to
do something special with it.

-- 
David Dorward  http://dorward.me.uk


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




Re: newbie question about regex

2004-09-03 Thread Maurice Lucas
Hello,
I call my script with the following line
$ ./count.pl /var/log/file text
this works fine but sometimes the "text" is "foo(bar)" and then my
scripts
gives an error.
 syntax error near unexpected token `foo(b'
I believe the syntax error is from your shell and you can get around
this by quoting your string to search on...
$ ./count.pl /var/log/file 'foo(bar)'
Should do it.
Sometimes,...
even the most simple problems could take several hours to understand until 
you ask and somebody's gives th right answer,

Thanks everybody for the quick and right answer
With kind regards,
Maurice Lucas
TAOS-IT 

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



Re: newbie question about regex

2004-09-03 Thread Wiggins d Anconia
> Hello,
> 
> I call my script with the following line
> $ ./count.pl /var/log/file text
> this works fine but sometimes the "text" is "foo(bar)" and then my
scripts 
> gives an error.
>  syntax error near unexpected token `foo(b'
> 

I believe the syntax error is from your shell and you can get around
this by quoting your string to search on...

$ ./count.pl /var/log/file 'foo(bar)'

Should do it.



http://danconia.org

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




Re: Newbie question

2004-08-03 Thread Paul Kraus
Go to a command prompt.Type 
ppm 
hit enter.
use this tool to install modules of windows.
On Sat, Jul 31, 2004 at 11:22:37PM -0500, Drue Reeves wrote:
> Sorry for the newbie question but, I'm having trouble using the Perldap
> module. I downloaded the binaries and I am trying to install them into
> ActiveState's latest version of Perl for Windows. I put the contents of
> blib/lib/Mozilla from the zip file in the Perl/lib directory (where the rest
> of the modules are).
> 
> When I try to run the qsearch.pl example script from I get these errors:
> 
> C:\Perl\blib\eg\PerLDAP>perl qsearch.pl
> 
> Can't locate loadable object for module Mozilla::LDAP::API in @INC (@INC
> contain
> s: C:/Perl/lib C:/Perl/site/lib .) at C:/Perl/lib/Mozilla/LDAP/Utils.pm line
> 29
> Compilation failed in require at C:/Perl/lib/Mozilla/LDAP/Utils.pm line 29.
> BEGIN failed--compilation aborted at C:/Perl/lib/Mozilla/LDAP/Utils.pm line
> 29.
> Compilation failed in require at C:/Perl/lib/Mozilla/LDAP/Conn.pm line 32.
> BEGIN failed--compilation aborted at C:/Perl/lib/Mozilla/LDAP/Conn.pm line
> 32.
> Compilation failed in require at qsearch.pl line 29.
> BEGIN failed--compilation aborted at qsearch.pl line 29.
> 
> Any help is appreciated.
> 
> Thank you,
> 
> Drue
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 


pgpjNHWDMdeny.pgp
Description: PGP signature


Re: newbie question about chomp...

2004-02-22 Thread WC -Sx- Jones
=pod

( R i c a r d o P i c h l e r ) wrote:
Hi people,
I can't make this work...
foreach $input()
{
chomp $input;
print "$input\n";
}
=cut

# hopefully it was previously opened.

while() {
  chomp;
  s/^\s//;
  s/\s$//;
  print "$_";
}
__END__

All this was asked and answered many times; please review the archives 
for CHOMP Newlines and/or Line endings...

HTH/Sx  =)

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



Re: Newbie question

2003-12-13 Thread Randal L. Schwartz
> "Michael" == Michael Sullivan <[EMAIL PROTECTED]> writes:

Michael> Can anyone recommend any free Perl tutorials?  I know almost nothing
Michael> about what I'm doing, only that it looks somewhat like C++...

Once you have the basics down, there are 198+ articles at
www.stonehenge.com/merlyn/columns.html that can enhance your knowledge.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> 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!

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




Re: Newbie question

2003-12-12 Thread drieux
On Dec 12, 2003, at 3:31 PM, Michael Sullivan wrote:

Can anyone recommend any free Perl tutorials?  I know almost nothing
about what I'm doing, only that it looks somewhat like C++...
a great place to start would be

	

There is a set of FAQs - the frequently asked questions.



will introduce you to 'the basic pod' with

being the Intro...
ciao
drieux
---

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



Re: Newbie Question! Can Someone help?

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

> Hello Fellow Members,
> 
> I'm installing a script on my domain for tech support for my program.
> 
> I understand all the install instructions except this?
> 
> For sendmail users, edit your aliases file and add this line.
> support: root,"|/path/to/your/openticket.pl"
> and than run, "newaliases"

No, it reads /etc/aliases and updates the alias database; try 'man
newaliases' for more info.

-K


-- 
Kevin Pfeiffer
International University Bremen


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



Re: Newbie question about the "int" operator

2003-06-14 Thread Rob Dixon
Mr.T Mr.X wrote:
> Well, first of all, I am replying to this address, because everytime I try to send 
> an email to the "group" i get it returned. 
> Where am I supposed to send my questions?  Well, in case its here, heres my Q: 
> 
> I am trying to work my way through the "Teach yourself PERL in 24
> hours" book, and at the end of chapter 2, it asks to make a number:
> 24.325613832 - change to only 2 decimal places (24.33)  So, how can I do this
> without using the printf command, (as the book asks to do it without
> using the printf command)?

This is my private mail address. Post to the list by mailing to the
address [EMAIL PROTECTED] I have forwarded this mail there.

>From your subject line it sounds like you know the answer already.
If you multiply the value up so that all the digits you want
are to the left of the decimal point then you can use 'int' before
scaling it back.

  my $val = 24.325613832;
  print int ($val * 100) / 100;

OUTPUT

  24.32

You question says the result should be 24.33, which is wrong - this
would involve rounding as well. If that's what you want, then think
how you could transform all values from 24.325 to 24.335 to something
between 2433.0 and 2433.99. Then you can use 'int' like I did above
and reverse the scaling.

HTH,

Rob





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



Re: NewBie Question! Please Help

2003-03-27 Thread Brett W. McCoy
On Thu, 27 Mar 2003, Palm Optins wrote:

> I writting a script so when members join my program it writes their
> Email Address into a flat file. I have it adding to the file this way.
>
> open (FILE, ">>$cgiroot/memdata/address/members.txt");
> flock(FILE, 2);
> print FILE "$list\n";
> flock(FILE, 8);
> close (FILE);

One danger I see here -- storing these addresses directly under the CGI
scripts directory.  Could be a serious security hole -- you should store
this stuff outside of your document root (and any directories aliased
under it).

-- Brett




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



Re: NewBie Question! Please Help

2003-03-27 Thread Rob Dixon
Palm Optins wrote:
> Hi All,
>
> I writting a script so when members join my program it writes their  Email Address 
> into a
> flat file. I have it adding to the file this way.

It's better to do

use Fcntl ':flock';

to get the names for the different lock vakues, then you can write:

> open (FILE, ">>$cgiroot/memdata/address/members.txt");
> flock(FILE, 2);

flock FILE, LOCK_EX;

> print FILE "$list\n";
> flock(FILE, 8);

flock FILE, LOCK_UN

> close (FILE);
>
> What I need to know, and I haven't been able to get it to work, is, How do I get it 
> to show
> one email address per line on a table in an HTML Page?

I think you want to read the text file and insert each line into a line of HTML?
If you can write HTML then you won't need me to tell you how to write a table,
so this just puts a line break after each line from the file. You also need an
HTTP Content Type header, the following will work:

You can do this:

{
print "Content-Type: text/html\n\n";

local @ARGV = $cgiroot/memdata/address/members.txt";
while (<>) {
chomp;
print "$_";
}
}

If you're doing anything much more complicated you might like to
take a look at one of Perl's CGI modules which makes things a lot
easier.

Come back if there's anything else you need.

Rob



> ¤§¤=¤§¤=¤§¤¤§¤=¤§¤=¤§¤
>
> For God so loved the world, that He gave his only begotten
> Son, that whosoever believeth in him should not perish, but
> have everlasting life.
>
> ¤§¤=¤§¤=¤§¤¤§¤=¤§¤=¤§¤

Amen




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



Re: NewBie Question! Please Help

2003-03-27 Thread Rob Dixon
Palm Optins wrote:
> Hi All,
>
> I writting a script so when members join my program it writes their  Email Address 
> into a
> flat file.
> I have it adding to the file this way.
>
> open (FILE, ">>$cgiroot/memdata/address/members.txt");
> flock(FILE, 2);
> print FILE "$list\n";
> flock(FILE, 8);
> close (FILE);
>
> What I need to know, and I haven't been able to get it to work, is, How do I get it 
> to show
> one email address per line
> on a table in an HTML Page?
>
> Thanks and God Bless
> Linda
> ICQ #: 179542247
>
> ¤§¤=¤§¤=¤§¤¤§¤=¤§¤=¤§¤
>
> For God so loved the world, that He gave his only begotten
> Son, that whosoever believeth in him should not perish, but
> have everlasting life.
>
> ¤§¤=¤§¤=¤§¤¤§¤=¤§¤=¤§¤





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



Re: Newbie question about modules

2003-02-18 Thread Todd Wade

"Rgíón «hávkú" <[EMAIL PROTECTED]> wrote in message
003001c2d474$f6f76b20$[EMAIL PROTECTED]">news:003001c2d474$f6f76b20$[EMAIL PROTECTED]...
> Hello all.
>
> I've reading some messges relating to the use of modules.
>
> How can I know what modules are installed in the server???
>
> I have my site hosted on a Server far away from here. And it provides me
> Perl with "the most commonly used modules". Being that I'm not an expert
on
> Perl I don't know what are the most commonly used modules. I have no
Telnet
> access, but only FTP, that has been quite enough for me.
>
> The obvious answer to my question is to "ask my hosting provider" this
info,
> but I think I'd prefeer a little more complex solution, if it exists.
>
> Is there a way I can find out this without asking my service provider??
>

of course. perldiver from scriptsolutions. Its a super slick CGI program.

http://www.scriptsolutions.com/programs/free/perldiver/

Just download the program, change the shebang and 755 the file.

Todd W.



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




Re: Newbie question about modules

2003-02-14 Thread david
Paul wrote:

>> How can I know what modules are installed in the server???
> 
> duh. Feeling dense.
> I think there should be a way, but can't think of how to get a full
> listing. Maybe the Config.pm?

try:

[xx@panda]$ perl -MFild::Find -e
'find(sub{print "$File::Find::name\n" if(/\.pm$/)},$_) for(@INC)'

this solution is not perfect and it only search what Perl consider to be 
standard directories for installed modules. there is nothing to stop a 
vendor from putting their customized modules in another location where Perl 
only have knowledge until run time and need to load the module.

david

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




Re: Newbie question about modules

2003-02-14 Thread Paul
> How can I know what modules are installed in the server???

duh. Feeling dense.
I think there should be a way, but can't think of how to get a full
listing. Maybe the Config.pm?

Anyway, to test for any *given* module(s), try

 perl -MModule::Name -e 'print "Module::Name is installed\n"'

thus, to see if the Damian's Coy.pm is available, use

 perl -MCoy -e 'print "Coy is installed\n"'

It will fail with errors if it isn't available.

__
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

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




Re: Newbie question

2003-02-12 Thread wiggins


On Wed, 12 Feb 2003 07:54:37 -0500, "Steve Lobach" <[EMAIL PROTECTED]> wrote:

> Thanks for replying.. 
> I can put perl on the Win 2000 desktops.. So I could, I suppose, use tk.pm and 
>Telnet.pm (found on cpan)... So from this point I think I can go forward.. 
> 

Out of curiousity is there a mail daemon on the server?  We run an encryption 
application that depends on security and prefer not to have a web server or even to 
have people logging in at all, but part of our application must have sendmail server 
(since it is email based) and we have found writing utility scripts to be rather 
trivial using sendmail. We simply set up an address alias to pipe the message to a 
perl script, parse the subject line of the email and the from address, this gives us 
enough authentication as we send the output back to that email address (which we make 
sure is only an internal email). The subject line contains the arguments to the script 
(in your case the query string). So then the end user only need know how to send email 
(which is a pretty common thing ;-)) and know what address to send to, and to put the 
proper arguments in teh subject line. In general our end user documentation fits on 
less than a sheet of paper.  Naturally this is not time sensitive!
 (as email isn't) but in general we have fast turn around, under 5 minutes of 
Groupwise wasn't so slow.  This also gives us a log of who is using the utility as the 
messages to that address can be tracked with the from address

http://danconia.org

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




Re: Newbie question

2003-02-12 Thread Daryl Field
I wouldn't go down this route - consider this:-

1. Number of desktops x installing Perl + then the required modules = too 
much work
2. Your putting a user readable script onto each machine - that script may 
contain login details, unless evryone has their own login anyway.

I would install a webserver & run it from there,
1. Everyone has a browser - so no legwork
2. For future needs you have a platform to roll stuff out on.

or write something that can be compiled into a binary app, either gui or 
console, easier to roll out & eminantly more secure.

& just so that I do actually mention Perl in this reply(which would seem 
apropriate), you can script to your hearts content on the webserver, 
preferably even on the IBM machine that's being queried.

Good luck,

Daryl

--On 11 February 2003 13:27 -0500 Steve Lobach <[EMAIL PROTECTED]> 
wrote:

I've been doing some work on AIX and using grep to find data in files,
but I frequently run into situations where the lines are much longer than
2k characters.  I found a nice tool using Perl to do this..

Now I would like to beef up this script a little bit..

How can I run that Perl script remotely without using Telnet?  Or maybe
hiding it by giving the end user a GUI?

These are my requirements..
1.  take a search string from enduser
2.  log into Unix
3.  execute Perl script
4.  return positive/negative result to user..


I don't have a web server for this.. I can install Perl on end user
desktops, but not preferred. Thanks,  Steve.



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







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




Re: Newbie question

2003-02-12 Thread Steve Lobach
Thanks for replying.. 
I can put perl on the Win 2000 desktops.. So I could, I suppose, use tk.pm and 
Telnet.pm (found on cpan)... So from this point I think I can go forward.. 

>>> Lance <[EMAIL PROTECTED]> 02/12/03 03:42AM >>>
My first thought is to make a little cgi script, but you don't have a
webserver...

What O/S is on the desktops?  More importantly, what scripting or
programming language do they have in common?  You can make a script or
program in you choice of language.  As long as it supports running other
languages and can recieve the output from them.



"Steve Lobach" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I've been doing some work on AIX and using grep to find data in files, but I
frequently run into situations where the lines are much longer than 2k
characters.  I found a nice tool using Perl to do this..

Now I would like to beef up this script a little bit..

How can I run that Perl script remotely without using Telnet?  Or maybe
hiding it by giving the end user a GUI?

These are my requirements..
1.  take a search string from enduser
2.  log into Unix
3.  execute Perl script
4.  return positive/negative result to user..


I don't have a web server for this.. I can install Perl on end user
desktops, but not preferred.
Thanks,  Steve.




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





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




Re: Newbie question

2003-02-12 Thread Lance
My first thought is to make a little cgi script, but you don't have a
webserver...

What O/S is on the desktops?  More importantly, what scripting or
programming language do they have in common?  You can make a script or
program in you choice of language.  As long as it supports running other
languages and can recieve the output from them.



"Steve Lobach" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I've been doing some work on AIX and using grep to find data in files, but I
frequently run into situations where the lines are much longer than 2k
characters.  I found a nice tool using Perl to do this..

Now I would like to beef up this script a little bit..

How can I run that Perl script remotely without using Telnet?  Or maybe
hiding it by giving the end user a GUI?

These are my requirements..
1.  take a search string from enduser
2.  log into Unix
3.  execute Perl script
4.  return positive/negative result to user..


I don't have a web server for this.. I can install Perl on end user
desktops, but not preferred.
Thanks,  Steve.




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




Re: Newbie question in Perl

2002-12-30 Thread R. Joseph Newton
Hi Anand,

Look at your logic:
until (($test ne 'Y') && ($test ne 'N') &&
 ($test ne 'y') && ($test ne 'n')) {...}  #until BAD input
This says that as long as there is good input, keep cyckling until you get bad input.  
You should either use while here, or change the condition to reflect the sought-after 
input:
until (($test eq 'Y') || ($test eq 'N') ||
 ($test eq 'y') || ($test eq 'n'))   #until GOOD input

Combined with the wrong test:
  if ($test eq 'N' || $test eq 'n')

What this says is:
Wait for the user to enter an bad response, then overwrite the file.
Since your contorl condition has insured that you will never get either Y, y, N, or n 
as input, whatever input you do receive will be sonething other than N or n, therefore 
your file will always be overwritten.  Remember, overwriting a file is destructive.  
Therefore test for y or Y.  If the user does not definitely say yes, you should not do 
it.

The until function is cute and all, but can be confusing.
while (you are not clear on the concept) {dont use it;}
until (you understand it better) {dont use it;}
One other point:  maybe your customers don't like being told what to do by a computer. 
 Most people despise it, in fact.  Let them type yes or no if they want, instead of 
just y or n:
if ($UserResponse =~ /^Y|^y/ ) {
  OverwriteOriginalFile();
} else {
  ExploreOtherOptions();
}
This would not proceed on "nay" for instance, but would go ahead on "yes", "yeah", 
"yep", "yuppers--you betchum!", and "yessireebob", as well as capitalized forms of any 
word starting with y..

Joseph


Anand Ramakrishna wrote:

>


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




Re: Newbie question in Perl

2002-12-30 Thread John W. Krahn
Anand Ramakrishna wrote:
> 
> 
> Hi,

Hello,

> I am a beginner to perl. I have written a simple program in Perl
> # This Program will copy the contents of a file named file.txt to another file
> # newfile.txt. If newfile.txt is already existing, the user is given an option
> # to overwrite the file and chose a new file name to write the output.
> 
> In this program, when I initially dont have a file named newfile.txt, it goes
> fine. If it finds a newfile.txt, then it prompts with a Warning message whether
> to overwrite or use another file name text.txt. From here if I give a command
> to overwrite, it works fine. If I give a command NO, it still overwrites the
> newfile.txt. Even if I give some invalid command other than Y or N it still
> overwrites that file. I am unable to fix this. Kindly help me in this regard.
> I have pasted the entire code below.
> 
> #!/usr/local/bin/perl

You should use warnings and strict when you are developing a perl
program.

use warnings;
use strict;


> # This Program will copy the contents of a file named file.txt to another file
> # newfile.txt. If newfile.txt is already existing, the user is given an option
> # to overwrite the file and chose a new file name to write the output.
> 
> # Open the first file file.txt
> 
>   open (FILE, "file.txt") || die ("ERROR !! file.txt does not exist\n");

"does not exist" is not the only reason that a file could not be
opened.  You should include the $! variable so that you know exactly why
the open failed.


> # Check for newfile.txt
> 
>   if (-e "newfile.txt")
> {
>   print "WARNING !! FILE newfile.txt already exists\n";
>   print "Do you want to destroy all the contents and overwrite the file\n";
>   print "Type Y for Yes or N or NO\n";
>   $test = ;
>   $test = chomp ($test);

chomp() returns the _number_ of characters removed.


> # Check if the command is either Yes or No. If not, be in the loop till
> # Yes or No command is given.
> 
>   until (($test ne 'Y') && ($test ne 'N') &&
>  ($test ne 'y') && ($test ne 'n'))
> {
>   print "Type Y for Yes or N for NO\n";
>   $test = ;
>   $test = chop ($test);

chop() returns the _character_ removed (in this case the newline
character.)


> }
> 
> # If command is NO, then ask if the contents will be copied in another file
> # name text.txt.
> 
>   if ($test eq 'N' || $test eq 'n')
> {
>   print "Do you want to write to another file named text.txt\n";
>   print "Type Y for Yes or N to quit\n";
>   $var = ;
>   $var = chop ($var);
> 
> # Check if the command is either Yes or No. If not, be in the loop till
> # Yes or No command is given.
> 
>   until ($var ne 'Y' && $var ne 'N' && $var ne 'y' && $var ne 'n')
> {
>   print "Type Y for Yes or N to quit\n";
>   $var = ;
>   $var = chomp ($var);
> }
> 
> # If command is YES, copy the contents to a new file called text.txt.
> # If command is NO quit program without copying.
> 
>   if ($var eq "Y" || $var eq "y")
> {
>   open (FILE1, ">text.txt");

You should _always_ verify that the file opened correctly.


>   $line1 = ;
> 
>   while ($line1 ne "")
> {
>   print FILE1 $line1;
>   $line1 = ;
> }

The correct way to write the while loop is:

   while ( my $line1 =  )
 {
   print FILE1 $line1;
 }

Or even:

   while (  )
 {
   print FILE1;
 }

Or even simply:

   print FILE1 while ;


>  }
>else
>  {
>die "Program terminated without copying the file\n";
>  }
> }
> 
> # Destroy the contents of newfile.txt and copy the contents in this file.
> 
>   else
> {
>open (FILE1, ">newfile.txt");

You should _always_ verify that the file opened correctly.


>$line1 = ;
> 
>while ($line1 ne "")
>  {
> print FILE1 $line1;
> $line1 = ;
>  }
> }
> }
> 
> # If newfile.txt does not exist, create a file in that name and copy the
> # contents to this file.
> 
>   else
> {
>   open (FILE1, ">newfile.txt");

You should _always_ verify that the file opened correctly.


>   $line1 = ;
> 
>   while ($line1 ne "")
> {
>print FILE1 $line1;
>$line1 = ;
> }
> }


This should do what you want:

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

# This Program will copy the contents of a file named file.txt to
another file
# newfile.txt. If newfile.txt is already existing, the user is given an
option
# to overwrite the file and chose a new file name to write the output.

my $o

Re: Newbie question in Perl

2002-12-30 Thread George P.



On Mon, 30 Dec 2002, Anand Ramakrishna wrote:

>   if (-e "newfile.txt")
> {
>   print "WARNING !! FILE newfile.txt already exists\n";
>   print "Do you want to destroy all the contents and overwrite the file\n";
>   print "Type Y for Yes or N or NO\n";
>   $test = ;
>   $test = chomp ($test);

chomp $test;
will chomp the last Control character in $test and return 1 or 0
depending on success or failure
What you are doing is chomping $test and then assigning the return
value to the variable, this way you lose the earlier value.

Instead of
>   $test = chomp ($test);
just use
chomp $test;

Same goes for chop
There are other occurences of chomp and chop, you will have to
change them also.





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




Re: Newbie question

2002-12-11 Thread John W. Krahn
Ashutosh Jog wrote:
> 
> Hello all,

Hello,

> I am a complete newbie and am trying to do a couple of things but was
> not able to. Any assitance is welcome.
> 
>  If I have a dir structure G:\abc\efg\qrs.txt:
> 
>  1) How can I list the entire structure under G:\abc along with all the dirs.
> under G:\abc\ right upto the file qrs.txt ?

Use the File::Find module to tranverse an entire directory tree.


> In this structure the dir name abc will not change and neither will the
> name of the file qrs.txt. But there will be a different dir name for efg
> for eg: there will be dirs as under
> G:\abc\efg\qrs.txt
> G:\abc\hij\qrs.txt ...etc. etc.
> 
> How can I have these listed in a file (line by line) using perl?
> 
>  2) Then I would want to take the individual dir names under G:\abc and
>  put them in a separate txt file.
>  For eg: From the above eg., I would like to have the dir's 'efg' and
>  'hij' listed in a diff txt file, line by line (i.e just these dir name)
> 
>  Is there a way to do so in perl? I could do the first part in shell
>  script but wasn't sure how it would work under perl. Thank you in
>  advance for your patience.


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

my $dir  = 'G:/abc';
my $file = 'qrs.txt';
my $out1 = 'list.txt';
my $out2 = 'dirs.txt';


open LIST1, '>', $out1 or die "Cannot open $out1: $!";
open LIST2, '>', $out2 or die "Cannot open $out2: $!";

opendir DIR, $dir or die "Cannot opendir $dir: $!";

while ( defined( my $ent = readdir DIR ) ) {
if ( -e "$dir/$ent/$file" ) {
print LIST1 "$dir/$ent/$file\n";
}
if ( -d "$dir/$ent" ) {
print LIST2 "$ent\n";
}
}

__END__




John
-- 
use Perl;
program
fulfillment

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




Re: Newbie Question

2002-10-16 Thread Dharmender Rai

Montana ,
  Read the ## part in ur attached mail below:

 --- montana <[EMAIL PROTECTED]>
wrote: > So looking at the following package:
> { package Horse;
>@ISA = qw(Animal);
>sub sound { "neigh" }
>sub name {
>  my $self = shift;
>  $$self;
>}
>sub named {
>  my $class = shift;
>  my $name = shift;
>  bless \$name, $class;
>}
>  }
> 
> followed by the following instantiation lines:
> 
> my $talking = Horse->named("Mr. Ed");
> print $talking->name, " says ", $talking->sound,
> "\n";
> 
> The only variable I see passed to the package is the
> name "Mr. Ed" which is in fact passed to the
> constructor "named" located in the package "Horse".
> Is this correct? 
### yeah
> So the constructor "named" takes the following list:
> 
> @_ = {Horse, "Mr. Ed"}
> 
> Is this correct?
## Yeah
> If so then "Horse" would be put
> into the scalar $class, and "Mr. Ed" would be put
> into the scalar $name. Is this correct? Ok so is
> $talking now an instance? And how does the
> "$talking->sound" produce "neigh"? Is the "@ISA"
> line and the sub name function needed in this
> package for Horse to still work, or is that there
> for inheritance purposes only?
## So you have finally read the perlboot :)
> Thanks.
> SA
> 
> P.S. I kind of try to work my questions out as I go
> along so sorry for the details if it is too much.
> 
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>  

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

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




Re: Newbie Question

2002-10-16 Thread montana

So looking at the following package:
{ package Horse;
   @ISA = qw(Animal);
   sub sound { "neigh" }
   sub name {
 my $self = shift;
 $$self;
   }
   sub named {
 my $class = shift;
 my $name = shift;
 bless \$name, $class;
   }
 }

followed by the following instantiation lines:

my $talking = Horse->named("Mr. Ed");
print $talking->name, " says ", $talking->sound, "\n";

The only variable I see passed to the package is the name "Mr. Ed" which is in fact 
passed to the constructor "named" located in the package "Horse". Is this correct? 
So the constructor "named" takes the following list:

@_ = {Horse, "Mr. Ed"}

Is this correct? If so then "Horse" would be put into the scalar $class, and "Mr. Ed" 
would be put into the scalar $name. Is this correct? Ok so is $talking now an 
instance? And how does the "$talking->sound" produce "neigh"? Is the "@ISA" line and 
the sub name function needed in this package for Horse to still work, or is that there 
for inheritance purposes only?

Thanks.
SA

P.S. I kind of try to work my questions out as I go along so sorry for the details if 
it is too much.


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




Re: Newbie Question.

2002-10-16 Thread Dharmender Rai

[1] pop takes out the elements from the right end of
the array while shift does that from the left end.
[2]When there is one element then the above mentioned
functions will give you the same result :)
[3] Yes, your notion about "my" is correct but for
more information go through the man pages on
www.perldoc.com or your system.
[4] Here @_ is the array (you are right about that
also). In this case you don't have to mention the name
of the array. 

Regards 

Dharmender Rai

 --- montana <[EMAIL PROTECTED]>
wrote: > I've been looking through the manual
perlboot. This
> is a beginners tutorial on Perl OOP.
> 
>  
> 
> One of the practice programs in this manual had the
> following line:
> my $class = shift;
> 
> This was located in the subroutine:
> sub Sheep::speak {...}
> 
> From what I've gathered so far, "my" makes the
> variable "$class" local to the subroutine only? Is
> this correct? "shift" takes the leftmost value out
> of a list and places it in the variable $class? Is
> this correct? If I got all of this correct, where is
> the array that shift is working on and why use shift
> instead of pop? Also what are the contents of this
> array and how can I see them? I know that that line
> of code places the value "Sheep" into "$class", I
> was just wondering how this works in plain English?
> I'm guessing, and please correct me if I'm wrong
> here, the array is "@_"? And this array contains the
> current class name "Sheep" as it's only item? And
> this is why "shift" and "pop" produce the same
> results?
> 
> Thanks in advance.
> SA
> 
> "I can do everything on my Mac that I used to do on
> my PC, plus alot more ..."
> --Me
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>  

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

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




RE: Newbie Question.

2002-10-16 Thread Duarte Cordeiro

Hi,
  don't know much about oo in perl, but a "regular" sub:
>From man perlsub:
[...]
All functions aree passead as parameters one single flat list os
scalars.
[...]
Any arguments passed in show up in the array '@_'.Therefor, if you
called a function with two arguments, those would be stored in '$_[0]
and $_[1].

Hope it helps,

Duarte


-Original Message-
From: montana [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, October 15, 2002 10:41 PM
To: [EMAIL PROTECTED]
Subject: Newbie Question.


I've been looking through the manual perlboot. This is a beginners
tutorial on Perl OOP.


One of the practice programs in this manual had the following line: my
$class = shift;

This was located in the subroutine:
sub Sheep::speak {...}

>From what I've gathered so far, "my" makes the variable "$class" local
to the subroutine only? Is this correct? "shift" takes the leftmost
value out of a list and places it in the variable $class? Is this
correct? If I got all of this correct, where is the array that shift is
working on and why use shift instead of pop? Also what are the contents
of this array and how can I see them? I know that that line of code
places the value "Sheep" into "$class", I was just wondering how this
works in plain English? I'm guessing, and please correct me if I'm wrong
here, the array is "@_"? And this array contains the current class name
"Sheep" as it's only item? And this is why "shift" and "pop" produce the
same results?

Thanks in advance.
SA

"I can do everything on my Mac that I used to do on my PC, plus alot
more ..." --Me

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




For your protection, this e-mail message has been scanned for viruses.
Visit us at http://www.neoris.com/

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




RE: Newbie Question.

2002-10-16 Thread Timothy Johnson


Yes, shift operates on @_ by default, which is also the array that contains
all arguments passed to the subroutine.  You are probably right that "Sheep"
is the only item in the list, due to the shift/pop behavior you mentioned.

-Original Message-
From: montana [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 15, 2002 2:41 PM
To: [EMAIL PROTECTED]
Subject: Newbie Question.


I've been looking through the manual perlboot. This is a beginners tutorial
on Perl OOP.


One of the practice programs in this manual had the following line:
my $class = shift;

This was located in the subroutine:
sub Sheep::speak {...}

>From what I've gathered so far, "my" makes the variable "$class" local to
the subroutine only? Is this correct? "shift" takes the leftmost value out
of a list and places it in the variable $class? Is this correct? If I got
all of this correct, where is the array that shift is working on and why use
shift instead of pop? Also what are the contents of this array and how can I
see them? I know that that line of code places the value "Sheep" into
"$class", I was just wondering how this works in plain English? I'm
guessing, and please correct me if I'm wrong here, the array is "@_"? And
this array contains the current class name "Sheep" as it's only item? And
this is why "shift" and "pop" produce the same results?

Thanks in advance.
SA

"I can do everything on my Mac that I used to do on my PC, plus alot more
"
--Me

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

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




Re: Newbie Question

2002-10-10 Thread Jean Padilla

Hi, James
Can you post some examples ?
- what do you call the header in your files,
- what string(s) are supposed to match what,
- what is the data to write to output file(s)
and so on...
Rgds.

James Parsons a écrit :
> 
> Hi all
> 
> Perl Is extremely new to me and I'm having a problem were to start..
>  I would like to create a script that  reads the header in each file in a
> directory and when it finds a match then redirects all of the data in the
> file to another file. Any help would be great..
> 
> thanks
> 
> James Parsons
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

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




Re: Newbie Question.

2002-10-07 Thread Dharmender Rai

Write the output from AppleScript in a file and from
that file your Perl Script can read the data. Also you
can invoke your Perl Script directly from AppleScript.



 --- montana <[EMAIL PROTECTED]>
wrote: > I am trying to combine the powers of
applescript and
> perl to better search data on some flat files.
> Because I'm using a Mac, I do not believe there is
> GUI toolkit for Perl and OSX "Aqua", so I'm using
> the GUI tools associated with AppleScript to gather
> the data from the user. Applescript will then
> collect the variables from the User and pass them to
> the perl script for processing. My question then, is
> how do you pass variables to perl script from the
> Unix command line and how are those variables
> processed within the script? More than likely, the
> variables will need to be passed to either an array
> or hash.
> 
> Thanks in Advance.
> SA
> :)
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>  

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

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




RE: Newbie Question.

2002-10-07 Thread david

Nkuipers wrote:

>>My question then, is how do you pass variables to perl script from the
>>Unix command line and how are those variables processed within the script?
>>More than likely, the variables will need to be passed to either an array
>>or hash.
> 
> Well, there are two main ways I know of to pass vars to Perl from the
> command
> line.  The first is where the entire script is contained on the command
> line,
> affectionately known as a "one-liner".  The second uses an array called
> @ARGV,
> which takes arguments passed after perl scriptname, in order.  For

some people perfer to set their args in the env. variable like:

$export WHATEVER=1234

and then in their script:

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

print "hi, i got: $ENV{'WHATEVER'} from you\n";

__END__

personally, i don't like it.

david

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




RE: Newbie Question.

2002-10-07 Thread nkuipers

>My question then, is how do you pass variables to perl script from the Unix
>command line and how are those variables processed within the script? More
>than likely, the variables will need to be passed to either an array or hash.

Well, there are two main ways I know of to pass vars to Perl from the command 
line.  The first is where the entire script is contained on the command line, 
affectionately known as a "one-liner".  The second uses an array called @ARGV, 
which takes arguments passed after perl scriptname, in order.  For example:

%perl yourscript filename someinteger

# $ARGV[0] contains filename
# $ARGV[1] contained someinteger

Within your script, for this example, you could access the vars as above, by 
index, or say something like

my $file = shift; #shifts off of @ARGV
my $int = shift; #shifts off of @ARGV again

There are also a couple of modules by the name of GetOpt::Std and GetOpt::Long 
that you may find very useful for parameter passing etc.

Regards,

Nathanael Kuipers


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




Re: Newbie Question

2002-09-18 Thread John W. Krahn

James Parsons wrote:
> 
> Ok since I'm new to Perl I've written this fairly simple script to add
> number from a text file, I have about 20-30 of these file with different
> names and I would like to know how to add this to my script, I know  how to
> do it  korn shell but in a perl script I'm really now sure, can  anyone
> point in the direction, Thanks for all your help..
> 
> script:
> #!/usr/bin/perl -w
> use strict;
> 
> my $total = 0;
> 
> open(FILE,"/usr/local/logs/onlines/mtd_temp") || die $!; # I have about 20
> mtd_temp1,2,3, etc
> $total += $_ while();
> 
> close(FILE);
> 
> my $value = 100;
> 
> $total = $total/$value;
> 
> printf  "\$$total\n",;



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

my $file = '/usr/local/logs/onlines/mtd_temp'   # I have about 20 mtd_temp1,2,3, etc
@ARGV = grep /^\Q$file\E\d+$/, glob "$file*";

my $total;
$total += $_ while <>;

my $value = 100;
$total = $total / $value;
print  "\$$total\n",;




John
-- 
use Perl;
program
fulfillment

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




Re: Newbie Question

2002-09-18 Thread Sudarshan Raghavan

On Wed, 18 Sep 2002, James Parsons wrote:

> Ok since I'm new to Perl I've written this fairly simple script to add
> number from a text file, I have about 20-30 of these file with different
> names and I would like to know how to add this to my script, I know  how to
> do it  korn shell but in a perl script I'm really now sure, can  anyone
> point in the direction, Thanks for all your help..
> 
>

Wrap this script by this and use $file in your open call
perldoc -f glob
perldoc -f File::Glob
while (my $file = ) {
}
 
> script: 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my $total = 0;
> 
> open(FILE,"/usr/local/logs/onlines/mtd_temp") || die $!; # I have about 20
> mtd_temp1,2,3, etc
> $total += $_ while();

The line read in from  will come in along with newline. This works 
because the string when treated as a number considers only the initial 
numric part. For e.g. the string "123abc" when evaluated as a number is 
123, "12\n" as a number is 12. 
 
For a clean code I would still recommend you chomp $_ (perldoc -f chomp)

> 
> close(FILE);
> 
> my $value = 100;
> 
> $total = $total/$value;
> 
> printf  "\$$total\n",;
> 
> etrprodcrm1pri /usr/local/sbin #


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




RE: Newbie question - Can smtp send attachments?

2002-09-05 Thread Yuen, Alex

Thanks to everyone for there help. I manage to get it to work for what I
need it for. Now onto other stuff.

:-)


> --
> From: Tim Musson[SMTP:[EMAIL PROTECTED]]
> Reply To: Tim Musson
> Sent: Wednesday, September 04, 2002 8:46 PM
> To:   [EMAIL PROTECTED]
> Subject:  Re: Newbie question - Can smtp send attachments?
> 
> Hey Alex, 
> 
> My MUA believes you used Internet Mail Service (5.5.2653.19)
> to write the following on Wednesday, September 4, 2002 at 2:39:07 PM.
> 
> YA> Hi,
> 
> YA> Having problems with just a simple test of MIME::Lite. Here is the
> output:
> 
> YA>
> **
> **
> YA> **
> YA> Global symbol "$msg" requires explicit package name at
> mimetest.pl
> YA> line 6.
> 
> Been having problems with my mail today so don't know if you have a
> response yet...  What is happening is from the 'use strict;' line.
> 
> Basically you want to 'scope' your variables.  Easiest way to take
> care of the err msg is put a 'my' in front of the $msg variable (and
> each one that gets a complaint).   Note: you only do this once in the
> current scope...
> 
> Once you do that and get it tested, run perldoc and check out the
> 'strict' and 'warnings' modules - you should always use them when
> working on your code.
> 
> YA> And here is the script:
> 
> YA>
> **
> **
> YA> **
> YA> #!/usr/local/bin/perl -w
> 
> YA> use MIME::Lite;
> YA> use strict;
>,,,--put the my here.
> YA> $msg = MIME::Lite->new(
> YA> From=>'[EMAIL PROTECTED]',
> YA> To  =>'[EMAIL PROTECTED]',
> YA> Subject =>'Testing MIME::Lite Module.',
> YA> Data=>"Successfully sent message."
> YA> );
> 
> YA> $msg->send;
> YA>
> **
> **
> YA> **
> YA> So, what does the output message mean?
> 
> 
> -- 
> [EMAIL PROTECTED]
> Flying with The Bat! eMail v1.61
> Windows 2000 5.0.2195 (Service Pack 2)
> The generation of random numbers is too important to be left to chance.
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

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




Re: Newbie question - Can smtp send attachments?

2002-09-04 Thread Tim Musson

Hey Alex, 

My MUA believes you used Internet Mail Service (5.5.2653.19)
to write the following on Wednesday, September 4, 2002 at 2:39:07 PM.

YA> Hi,

YA> Having problems with just a simple test of MIME::Lite. Here is the output:

YA> 
YA> **
YA> Global symbol "$msg" requires explicit package name at mimetest.pl
YA> line 6.

Been having problems with my mail today so don't know if you have a
response yet...  What is happening is from the 'use strict;' line.

Basically you want to 'scope' your variables.  Easiest way to take
care of the err msg is put a 'my' in front of the $msg variable (and
each one that gets a complaint).   Note: you only do this once in the
current scope...

Once you do that and get it tested, run perldoc and check out the
'strict' and 'warnings' modules - you should always use them when
working on your code.

YA> And here is the script:

YA> 
YA> **
YA> #!/usr/local/bin/perl -w

YA> use MIME::Lite;
YA> use strict;
   ,,,--put the my here.
YA> $msg = MIME::Lite->new(
YA> From=>'[EMAIL PROTECTED]',
YA> To  =>'[EMAIL PROTECTED]',
YA> Subject =>'Testing MIME::Lite Module.',
YA> Data=>"Successfully sent message."
YA> );

YA> $msg->send;
YA> 
YA> **
YA> So, what does the output message mean?


-- 
[EMAIL PROTECTED]
Flying with The Bat! eMail v1.61
Windows 2000 5.0.2195 (Service Pack 2)
The generation of random numbers is too important to be left to chance.


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




Re: Newbie question - Can smtp send attachments?

2002-09-04 Thread James Edward Gray II

It means that you need a "my" before your $msg variables' first use.  
You predeclared "use strict" promising Perl you would declare your 
variables before using them.  "my $msg" would declare a local variable 
so you can use it.

James

On Wednesday, September 4, 2002, at 01:39  PM, Yuen, Alex wrote:

>   Global symbol "$msg" requires explicit package name at mimetest.pl
> line 6.
>
>   my $msg = MIME::Lite->new( # declare and use


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




RE: Newbie question - Can smtp send attachments?

2002-09-04 Thread david

Alex Yuen wrote:

> #!/usr/local/bin/perl -w
> 
> use MIME::Lite;
> use strict;
> 
> $msg = MIME::Lite->new(
> From  =>'[EMAIL PROTECTED]',
> To=>'[EMAIL PROTECTED]',
> Subject   =>'Testing MIME::Lite Module.',
> Data  =>"Successfully sent message."
> );
> 
> $msg->send;
> 

> **

this is Perl trying to tell you that before you can use the $msg variable, 
you need to declare it. the 'use strict' thing enforce that. change:

$msg = MINE::Lite->new(

to:

my $msg = MINE::List->new(

and try again.

david

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




RE: Newbie question - Can smtp send attachments?

2002-09-04 Thread Yuen, Alex

Hi, 

Having problems with just a simple test of MIME::Lite. Here is the output:


**
Global symbol "$msg" requires explicit package name at mimetest.pl
line 6.
Global symbol "$msg" requires explicit package name at mimetest.pl
line 13.
Execution of mimetest.pl aborted due to compilation errors.

**

And here is the script:


**
#!/usr/local/bin/perl -w

use MIME::Lite;
use strict;

$msg = MIME::Lite->new(
From=>'[EMAIL PROTECTED]',
To  =>'[EMAIL PROTECTED]',
Subject =>'Testing MIME::Lite Module.',
Data=>"Successfully sent message."
);

$msg->send;

**
So, what does the output message mean?

Thanks.

Alex


> --
> From: Bob Showalter[SMTP:[EMAIL PROTECTED]]
> Sent:     Wednesday, September 04, 2002 11:33 AM
> To:   '[EMAIL PROTECTED]'
> Subject:  RE: Newbie question - Can smtp send attachments?
> 
> > -Original Message-
> > From: Yuen, Alex [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, September 04, 2002 11:17 AM
> > To: 'Perl Beginners'
> > Subject: Newbie question - Can smtp send attachments?
> > 
> > 
> > Hi,
> > 
> > Is it possible to send attachments using NET::SMTP? 
> 
> Well, yes. But SMTP doesn't really know or care about "attachments". The
> trick is to prepare a multipart MIME message that contains the attachments
> and then send that using SMTP.
> 
> > 
> > Will I need to use a seperate module in my script? If so, 
> > which one and how?
> 
> I like MIME::Lite. Download from CPAN and read the docs. Very simple to
> use.
> It can do the sending, or you can use Net::SMTP to send the message if you
> like.
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

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




Re: Newbie question - Can smtp send attachments?

2002-09-04 Thread Frank Wiles

 .--[ Yuen, Alex wrote (2002/09/04 at 11:16:30) ]--
 | 
 |  Is it possible to send attachments using NET::SMTP? 
 |  
 |  Will I need to use a seperate module in my script? If so, which one and how?
 |  
 `-

It's not really possible to do with Net::SMTP.  I would suggest
you take a look at MIME::Lite, it makes it very very easy. 

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


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




RE: Newbie question - Can smtp send attachments?

2002-09-04 Thread Bob Showalter

> -Original Message-
> From: Yuen, Alex [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 04, 2002 11:17 AM
> To: 'Perl Beginners'
> Subject: Newbie question - Can smtp send attachments?
> 
> 
> Hi,
> 
> Is it possible to send attachments using NET::SMTP? 

Well, yes. But SMTP doesn't really know or care about "attachments". The
trick is to prepare a multipart MIME message that contains the attachments
and then send that using SMTP.

> 
> Will I need to use a seperate module in my script? If so, 
> which one and how?

I like MIME::Lite. Download from CPAN and read the docs. Very simple to use.
It can do the sending, or you can use Net::SMTP to send the message if you
like.

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




RE: Newbie question on smtp...

2002-09-04 Thread Yuen, Alex

Never mind...figured it out.

Stupid error with the # sign.

Thanks though.

Alex


> --
> From: Yuen, Alex
> Sent: Wednesday, September 04, 2002 10:11 AM
> To:   'Perl Beginners'
> Subject:  Newbie question on smtp...
> 
> I am having problems with smtp. I am trying to do a simple test from the
> documentation and can't figure out why it is not working. I get this error
> message:
> 
>   Can't call method "mail" on an undefined value at windowstest_07.pl
> line 10.
> 
> Here is what I have.
> 
> **
> ***
>   #!/usr/local/bin/perl -w
> 
>   use Net::SMTP;
> 
>   # Section determines the domain name of smtp server.
>   # $smtp = Net::SMTP->new('mailhost');
>   # print $smtp->domain,"\n";
>   # $smtp->quit;
> 
>   $smtp->mail('[EMAIL PROTECTED]');
>   $smtp->to('[EMAIL PROTECTED]');
> 
>   $smtp->data();
>   $smtp->datasend("To: [EMAIL PROTECTED]\n");
>   $smtp->datasend("\n");
>   $smtp->datasend("A simple test message\n");
>   $smtp->datasend();
> 
>   $smtp->quit;
> **
> ***
> This seems simple enough, but keep getting this error message.
> 
> Using ActivePerl version 5.6. 
> 
> Thanks.
> 
> Alex
> 
> 
> 
> 
> 

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




RE: Newbie Question - Monitoring NT Server(s) andNotification...

2002-08-28 Thread Kipp, James

have you looked at the modules:
Win32::Perflib
Win32::Lanman
Win32::AdminMisc

Those 3 should give you most of what you need. Read the docs for them and
google for examples. the examples in the docs are pretty good. also see the
following links for help and examples:
http://patriot.net/~carvdawg/perl.html
http://www.roth.net

> -Original Message-
> From: Yuen, Alex [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 28, 2002 11:43 AM
> To: 'Perl Beginners'
> Subject: Newbie Question - Monitoring NT Server(s) and Notification...
> 
> 
> Hi All,
> 
> I am also a newbie and looking to get a good start on how to 
> actually write
> a Perl script to do what I need.
> 
> I am looking to setup a script to monitor a NT Server(s) for:
> CPU usage notify if heavily used
> Memory usage  notify if heavily used
> HardDrive space   notify if using up to a certain 
> percentage, like 80%
> utilization
> Server reboot notify when a server is rebooted or comes down
> Server down   notify if and when a server is not 
> responding (if
> possible)
> Application   notify if an application is down (if possible)
> 
> Plus others possibilities that can be used.
> 
> I have read most of the documentation, but confused at what 
> to use and how
> to start. I learn faster by actually doing it from a good 
> starting point,
> but I don't know where to begin on this one.
> 
> Any suggestions to get me started would be greatly appreciated.
> 
> Thanks.
> 
> Alex
> 
> 
> Life is grand...don't let it pass you by.
> Enjoy life...second chances don't always come around.
> :-)
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


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




Re: Newbie Question.

2002-08-27 Thread Omanakuttan

open (FH, $filename) or die $! ;
my @arr =  ;

HTH.
Om.


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




Re: Newbie Question.

2002-08-27 Thread John W. Krahn

From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
> 
> Hi,

Hello,

> Another question:
> 
> If I have a hash with entries like these:
> 
> my %hash = ($animals [0]=> [$mammals[0]], $animals[1] => [$mammals[1]]);
> 
> But if the list has like 50 entries in both the $animals & $mammals the can
> I do
> this?
> 
> my %hash = ($animals [0..49]=> [$mammals[0..49]]);
> 
> What I want to avoid is the number of time I have to type in the %hash
> entries.
> It did not seem to work well.


When you want an array slice or a hash slice you have to use @ instead
of $ in front of the name.

my %hash;
@hash{ @animals[0..49] } = @mammals[0..49];


perldoc perldata



John
-- 
use Perl;
program
fulfillment

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




RE: Newbie Question.

2002-08-27 Thread Timothy Johnson


I think you can simplify this with a loop:

  for($i = 0;$i < @animals;$i++){
$hash{$animals[$i]} = $mammals[$i];
  }

-Original Message-
From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 27, 2002 2:33 PM
To: Timothy Johnson
Subject: Re: Newbie Question.


Hi,

Another question:

If I have a hash with entries like these:

my %hash = ($animals [0]=> [$mammals[0]], $animals[1] => [$mammals[1]]);

But if the list has like 50 entries in both the $animals & $mammals the can
I do
this?

my %hash = ($animals [0..49]=> [$mammals[0..49]]);

What I want to avoid is the number of time I have to type in the %hash
entries.
It did not seem to work well.

Thanks.



Timothy Johnson wrote:

> By the way, you have your phone number attached to your messages.  You
might
> want to be careful with that.
>
> -Original Message-
> From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 27, 2002 10:19 AM
> To: Timothy Johnson
> Subject: Re: Newbie Question.
>
> Thanksgot you.
>
> Timothy Johnson wrote:
>
> > That's easy enough.  Try something like this:
> >
> >   open(INFILE,"zoo.txt");
> >   @animals = ;
> >
> > Perl will automatically dump the entire contents of the file into the
> array,
> > with each line as an element.  But beware!  If you try to do this with
> > extremely large files, you can really bog down your program.  In many
> cases
> > it's better to loop through the file line by line using the
> > "while(){" syntax.
> >
> > Note:  If you don't want the "\n" character at the end of each line to
> show
> > up in your variables, you should also do a "chomp(@array)".
> >
> > -Original Message-
> > From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, August 27, 2002 10:09 AM
> > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> > Subject: Newbie Question.
> >
> > Hello,
> >
> > This might be a very simple question, but being a newbie I have to ask.
> > :)
> >
> > How can I copy the line by line contents of a file to a array?
> >
> > For eg: @animals should look like
> > @animals = ('tiger','lion','elephant');
> >
> > And the text file would have entries for the same in this order (i.e.
> > one after the other):
> >
> > tiger
> > lion
> > elephant
> >
> > Thanks in advance.

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




Re: Newbie Question.

2002-08-27 Thread John W. Krahn

Ashutosh Jog wrote:
> 
> Hello,

Hello,

> This might be a very simple question, but being a newbie I have to ask.
> :)
> 
> How can I copy the line by line contents of a file to a array?
> 
> For eg: @animals should look like
> @animals = ('tiger','lion','elephant');
> 
> And the text file would have entries for the same in this order (i.e.
> one after the other):
> 
> tiger
> lion
> elephant


You could use the Tie::File module.

use Tie::File;

tie @animals, 'Tie::File', 'filename' or die ...;



John
-- 
use Perl;
program
fulfillment

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




Re: Newbie Question.

2002-08-27 Thread Steve Grazzini

Ashutosh Jog <[EMAIL PROTECTED]> wrote:
> 
> This might be a very simple question, but being a newbie I 
> have to ask.  :)
> 
> How can I copy the line by line contents of a file to a array?
> 
> For eg: @animals should look like
> @animals = ('tiger','lion','elephant');
> 
> And the text file would have entries for the same in this order 
> (i.e. one after the other):
> 
> tiger
> lion
> elephant

  open ANIMALS, $filename  or die "open: $filename: $!";
  chomp( my @animals =  );

But if, as often happens, you end up looping over the array
once and then ignoring it, consider this instead:

  while () {
 chomp;
 # something interesting
  }

Which doesn't have to read the file into memory in order 
to loop over each line.

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

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




RE: Newbie Question.

2002-08-27 Thread Timothy Johnson


That's easy enough.  Try something like this:

  open(INFILE,"zoo.txt");
  @animals = ;

Perl will automatically dump the entire contents of the file into the array,
with each line as an element.  But beware!  If you try to do this with
extremely large files, you can really bog down your program.  In many cases
it's better to loop through the file line by line using the
"while(){" syntax.

Note:  If you don't want the "\n" character at the end of each line to show
up in your variables, you should also do a "chomp(@array)".

-Original Message-
From: Ashutosh Jog [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 27, 2002 10:09 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Newbie Question.


Hello,

This might be a very simple question, but being a newbie I have to ask.
:)

How can I copy the line by line contents of a file to a array?

For eg: @animals should look like
@animals = ('tiger','lion','elephant');


And the text file would have entries for the same in this order (i.e.
one after the other):

tiger
lion
elephant


Thanks in advance.


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




RE: newbie question

2002-08-20 Thread Dharmendra Rai


hi ,

 that's correct . 

$| can have only 2 values. either 1 or 0. its undocumented but the behaviour is same 
everywhere.

 




-
Get a bigger mailbox -- choose a size that fits your needs.

http://uk.docs.yahoo.com/mail_storage.html


Re: newbie question

2002-08-20 Thread Steve Grazzini

David <[EMAIL PROTECTED]> wrote:
> i agree. the part that make people confuse is that most people 
> think $| is a variable holding a number. that's not necessary 
> the case. Perl could have(easily) implmented $| to be a bit
> (save memory and faster access and manipulation etc) position 
> of a number. many c functions does that.

It *is* a bit, actually...

Perl filehandles look like:

struct xpvio {

[ big snip ]

longxio_lines;  /* $. */
longxio_page;   /* $% */
longxio_page_len;   /* $= */
longxio_lines_left; /* $- */
char *  xio_top_name;   /* $^ */
GV *xio_top_gv; /* $^ */
char *  xio_fmt_name;   /* $~ */
GV *xio_fmt_gv; /* $~ */
char *  xio_bottom_name;/* $^B */
GV *xio_bottom_gv;  /* $^B */
short   xio_subprocess; /* -| or |- */
charxio_type;
charxio_flags;
};

The "autoflush" for a given filehandle is a bit in the 
xio_flags, and get/setting $| just toggles that bit.

It affects the "default" filehandle, which is STDOUT
or whatever you select().

And see also the IO::Handle manpage... all these magic
globals to influence the "current" or "default" filhandle
turn into well-behaved, orderly methods of that class.

> when you assign something to it, it merely sets this bit 
> to 0 or 1 but not actually assigne any value to it. 

Exactly.  The actual value you assign is ignored, and only
tested for truth/falseness.

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

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




Re: newbie question

2002-08-20 Thread Steve Grazzini

John W. Krahn <[EMAIL PROTECTED]> wrote:
> Kevin Meltzer wrote:

[ back and forth ]

>> >>> > This is actually a bug. It just seems that nobody seems to 
>> >>> > care :) It would break too many JAPHs which use this.
>> >>> >
>> >>> > So, don't depend on it, in case it is ever fixed.
>> >>>
>> >>> Can you cite a reference to this behavior described as a bug?
>> >>
>> >> Does that behavior not seem like a bug to you?
>> >
>> > Not necessarily.  :-)
>> 
>> I'm curious as to why. When I mentioned it on channel, a few people
>> didn't see it as a bug either, at first. Being that it is using -- 
>> in a way which isn't consistent with -- (it increments as opposed to
>> decrement). In fact, it isn't just with --/++ but + and - will yield
>> the same results. Anyways, just curious why you think that subtracting
>> from 0 yields a 1 doesn't seem like a bug (and when adding 1 never
>> yields a 0).
> 
> Well, because Perl has lots of special cases like this.  Most people
> don't ever use $| let alone the special properties of $|--.  The average
> programmer just needs to know that setting $| to 1 turns on autoflush
> and setting $| to 0 turns off autoflush.  What about the fact that ++
> will increment a string but -- will not decrement it?

My 2p:

$| is a boolean.  It's an alias to a *bit*.

And I'm not sure what the best semantic for $bool-- 
would be, but two possibilities come to mind:

- make it falser

  This might be kind of nice, actually.  

  $|-- would always turn autoflushing off.

- treat it as zero and decrement it

  This is what it does now.

  "But that's not what it does now!"

Sure it is:

Any non-zero number is "true", so decrementing zero
has to yield a "true" value.

  $x = 0;  # false
  $x--;# true

And just so with $|:

  $| = 0;  # false
  $|--;# true  

If you ignore what the numeric value is afterward, 
this does exactly what it should.

Obviously, the fact that the numeric value is *one*
afterward is a little jarring.  But maybe it's best
if you don't think of $| as ever being zero or one.

Think of it as a "pure" boolean, which gets 
temporarily coerced to zero or one when you use 
it in a non-boolean context.  

And anyway...

$^W behaves the same way so it can't be a bug.  :)

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

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




Re: newbie question

2002-08-20 Thread Kevin Meltzer

Show me that $| can have a value other than 1 or 0 :) Same with $^W,
which has the same behavior. I can see that, in a way, it makes sense..
since $|-- would make it -1, which is a true value and since $| can
only be 1|0 it becomes 1, since that is a true value. But, I still
don't like it :) Especially with $^W.

If something isn't documented, it is either a bug or a feature, once
documented it is a feature :)

Cheers,
Kevin

On Tue, Aug 20, 2002 at 05:38:02PM -0400, Nikola Janceski 
([EMAIL PROTECTED]) said something similar to:
> It's not a bug as I see it. You gurus must have told the compiler that $|
> can only hold a 0 or 1 for whatever reason;
> 
> Just because something isn't documented, doesn't make it a bug.
> 
> But even in the docs it tells you,
> "The following names have special meaning to Perl."
> Translation: "Don't do crap with it, unless it's for it's special purpose."
> 
> 
> > -Original Message-
> > From: John W. Krahn [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, August 20, 2002 5:22 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: newbie question
> > 
> > 
> > Kevin Meltzer wrote:
> > > 
> > > I'm curious as to why. When I mentioned it on channel, a few people
> > > didn't see it as a bug either, at first. Being that it is 
> > using -- in a
> > > way which isn't consistent with -- (it increments as opposed to
> > > decrement). In fact, it isn't just with --/++ but + and - will yield
> > > the same results. Anyways, just curious why you think that 
> > subtracting
> > > from 0 yields a 1 doesn't seem like a bug (and when adding 1 never
> > > yields a 0).
> > 
> > Well, because Perl has lots of special cases like this.  Most people
> > don't ever use $| let alone the special properties of $|--.  
> > The average
> > programmer just needs to know that setting $| to 1 turns on autoflush
> > and setting $| to 0 turns off autoflush.  What about the fact that ++
> > will increment a string but -- will not decrement it?
> > 
> 
> 
> 
> The views and opinions expressed in this email message are the sender's
> own, and do not necessarily represent the views and opinions of Summit
> Systems Inc.
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
"As the fletcher whittles and makes straight his arrows, so the master directs
his straying thoughts." 
-- Buddha

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




RE: newbie question

2002-08-20 Thread david

i agree. the part that make people confuse is that most people think $| is a 
variable holding a number. that's not necessary the case. Perl could 
have(easily) implmented $| to be a bit(save memory and faster access and 
manipulation etc) position of a number. many c functions does that.

when you assign something to it, it merely sets this bit to 0 or 1 but not 
actually assigne any value to it. 

just some thought...

david

Nikola Janceski wrote:

> It's not a bug as I see it. You gurus must have told the compiler that $|
> can only hold a 0 or 1 for whatever reason;
> 
> Just because something isn't documented, doesn't make it a bug.
> 
> But even in the docs it tells you,
> "The following names have special meaning to Perl."
> Translation: "Don't do crap with it, unless it's for it's special
> purpose."
> 
> 
>> -Original Message-
>> From: John W. Krahn [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, August 20, 2002 5:22 PM
>> To: [EMAIL PROTECTED]
>> Subject: Re: newbie question
>> 
>> 
>> Kevin Meltzer wrote:
>> > 
>> > I'm curious as to why. When I mentioned it on channel, a few people
>> > didn't see it as a bug either, at first. Being that it is
>> using -- in a
>> > way which isn't consistent with -- (it increments as opposed to
>> > decrement). In fact, it isn't just with --/++ but + and - will yield
>> > the same results. Anyways, just curious why you think that
>> subtracting
>> > from 0 yields a 1 doesn't seem like a bug (and when adding 1 never
>> > yields a 0).
>> 
>> Well, because Perl has lots of special cases like this.  Most people
>> don't ever use $| let alone the special properties of $|--.
>> The average
>> programmer just needs to know that setting $| to 1 turns on autoflush
>> and setting $| to 0 turns off autoflush.  What about the fact that ++
>> will increment a string but -- will not decrement it?
>> 
> 
> 

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


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




RE: newbie question

2002-08-20 Thread Nikola Janceski

It's not a bug as I see it. You gurus must have told the compiler that $|
can only hold a 0 or 1 for whatever reason;

Just because something isn't documented, doesn't make it a bug.

But even in the docs it tells you,
"The following names have special meaning to Perl."
Translation: "Don't do crap with it, unless it's for it's special purpose."


> -Original Message-
> From: John W. Krahn [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 20, 2002 5:22 PM
> To: [EMAIL PROTECTED]
> Subject: Re: newbie question
> 
> 
> Kevin Meltzer wrote:
> > 
> > I'm curious as to why. When I mentioned it on channel, a few people
> > didn't see it as a bug either, at first. Being that it is 
> using -- in a
> > way which isn't consistent with -- (it increments as opposed to
> > decrement). In fact, it isn't just with --/++ but + and - will yield
> > the same results. Anyways, just curious why you think that 
> subtracting
> > from 0 yields a 1 doesn't seem like a bug (and when adding 1 never
> > yields a 0).
> 
> Well, because Perl has lots of special cases like this.  Most people
> don't ever use $| let alone the special properties of $|--.  
> The average
> programmer just needs to know that setting $| to 1 turns on autoflush
> and setting $| to 0 turns off autoflush.  What about the fact that ++
> will increment a string but -- will not decrement it?
> 



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


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




Re: newbie question

2002-08-20 Thread Kevin Meltzer

On Mon, Aug 19, 2002 at 05:17:05PM -0700, John W. Krahn ([EMAIL PROTECTED]) said 
something similar to:
> Kevin Meltzer wrote:
> > 
> > On Mon, Aug 19, 2002 at 04:35:53PM -0700, John W. Krahn ([EMAIL PROTECTED]) said 
>something similar to:
> > > Kevin Meltzer wrote:
> > > >
> > > > This is actually a bug. It just seems that nobody seems to care :) It
> > > > would break too many JAPHs which use this.
> > > >
> > > > So, don't depend on it, in case it is ever fixed.
> > >
> > > Can you cite a reference to this behavior described as a bug?
> > 
> > Does that behavior not seem like a bug to you?
> 
> Not necessarily.  :-)
 
I'm curious as to why. When I mentioned it on channel, a few people
didn't see it as a bug either, at first. Being that it is using -- in a
way which isn't consistent with -- (it increments as opposed to
decrement). In fact, it isn't just with --/++ but + and - will yield
the same results. Anyways, just curious why you think that subtracting
from 0 yields a 1 doesn't seem like a bug (and when adding 1 never
yields a 0).

Cheers,
Kevin

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
You have just destroyed one model XQJ-37 nuclear powered pansexual
roto-plookerand you're gonna have to pay for it.
-- Frank Zappa

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




Re: newbie question

2002-08-19 Thread John W. Krahn

Kevin Meltzer wrote:
> 
> On Mon, Aug 19, 2002 at 04:35:53PM -0700, John W. Krahn ([EMAIL PROTECTED]) said 
>something similar to:
> > Kevin Meltzer wrote:
> > >
> > > This is actually a bug. It just seems that nobody seems to care :) It
> > > would break too many JAPHs which use this.
> > >
> > > So, don't depend on it, in case it is ever fixed.
> >
> > Can you cite a reference to this behavior described as a bug?
> 
> Does that behavior not seem like a bug to you?

Not necessarily.  :-)

> My reference is
> discussions on #perl about it. I'll dig up the logs if you wish (when I
> can get to that).

That's Ok, it's no big deal.


John
-- 
use Perl;
program
fulfillment

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




Re: newbie question

2002-08-19 Thread Kevin Meltzer

Does that behavior not seem like a bug to you? My reference is
discussions on #perl about it. I'll dig up the logs if you wish (when I
can get to that).

Cheers,
Kevin

On Mon, Aug 19, 2002 at 04:35:53PM -0700, John W. Krahn ([EMAIL PROTECTED]) said 
something similar to:
> Kevin Meltzer wrote:
> > 
> > This is actually a bug. It just seems that nobody seems to care :) It
> > would break too many JAPHs which use this.
> > 
> > So, don't depend on it, in case it is ever fixed.
> 
> Can you cite a reference to this behavior described as a bug?
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
All people have the right to be stupid, some people just abuse it!
-- Frank Zappa

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




Re: newbie question

2002-08-19 Thread John W. Krahn

Kevin Meltzer wrote:
> 
> This is actually a bug. It just seems that nobody seems to care :) It
> would break too many JAPHs which use this.
> 
> So, don't depend on it, in case it is ever fixed.

Can you cite a reference to this behavior described as a bug?


John
-- 
use Perl;
program
fulfillment

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




Re: newbie question

2002-08-19 Thread Kevin Meltzer


This is actually a bug. It just seems that nobody seems to care :) It
would break too many JAPHs which use this.

So, don't depend on it, in case it is ever fixed. 
On Mon, Aug 19, 2002 at 01:17:15PM -0700, John W. Krahn ([EMAIL PROTECTED]) said 
something similar to:
> Bob Showalter wrote:
> Also, $| has an interesting property when you decrement it.
> 
> $ perl -le'for (1 .. 6) {$|--; print $|}'
> 1
> 0
> 1
> 0
> 1
> 0
> 


The following makes sense, since $| only has a range of [0,1], it
should stay at 1.. unlike the $-- bug.

> $ perl -le'for (1 .. 6) {$|++; print $|}'
> 1
> 1
> 1
> 1
> 1
> 1

Cheers,
Kevin

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
Number one ain't you... You ain't even number two.
-- Frank Zappa

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




RE: newbie question

2002-08-19 Thread Bob Showalter

> -Original Message-
> From: John W. Krahn [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 19, 2002 4:17 PM
> To: [EMAIL PROTECTED]
> Subject: Re: newbie question
> 
> 
> Bob Showalter wrote:
> > 
> > ...consider if $| were -1 prior to the increment).
>^
> 
> It's not going to happen Bob!  :-)  $| is very magical and 
> can only hold
> the values zero and one.
> 
> $ perl -le'for (-5, -1, 0, 1, 5) {$| = $_; print $|}'
> 1
> 1
> 0
> 1
> 1
> 
> 
> Also, $| has an interesting property when you decrement it.
> 
> $ perl -le'for (1 .. 6) {$|--; print $|}'
> 1
> 0
> 1
> 0
> 1
> 0
> 
> Which it doesn't have when you increment it.
> 
> $ perl -le'for (1 .. 6) {$|++; print $|}'
> 1
> 1
> 1
> 1
> 1
> 1

In the words of Johnny Carson, "I did not know that!". :~) Thanks for
educating me.

I'm stickin by my story though. I would use $| = 1 and $| = 0 to make sure
that Perl DWIM!

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




Re: newbie question

2002-08-19 Thread John W. Krahn

Bob Showalter wrote:
> 
> > From: Chad Kellerman [mailto:[EMAIL PROTECTED]]
> >
> >I have only been writing perl for a few months, so forgive
> > me if this
> > sounds stupid.
> 
> No, it's an excellent question.
> 
> > what is the difference between:
> >
> > $| = 1;
> > and
> > $|++;
> 
> The first assigns the value 1 to the variable $|
> The second increments (adds 1 to) the current value of $|
> 
> $| is a "special" variable to Perl. It controls the automatic flushing of
> output filehandles after a print(). The default is 0, which means no
> auto-flush. Setting it to 1 (or any non-zero value) enables the
> auto-flushing.
> 
> Assuming these statements appeared at the top of the program, the effect
> would be the same for each. I prefer the first form to the second, since it
> is not dependent on what other code may or may not be doing to $| (i.e.
> consider if $| were -1 prior to the increment).
   ^

It's not going to happen Bob!  :-)  $| is very magical and can only hold
the values zero and one.

$ perl -le'for (-5, -1, 0, 1, 5) {$| = $_; print $|}'
1
1
0
1
1


Also, $| has an interesting property when you decrement it.

$ perl -le'for (1 .. 6) {$|--; print $|}'
1
0
1
0
1
0

Which it doesn't have when you increment it.

$ perl -le'for (1 .. 6) {$|++; print $|}'
1
1
1
1
1
1




John
-- 
use Perl;
program
fulfillment

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




RE: newbie question

2002-08-19 Thread Bob Showalter

> -Original Message-
> From: Chad Kellerman [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 19, 2002 11:18 AM
> To: [EMAIL PROTECTED]
> Subject: newbie question
> 
> 
>   Hello,
> 
>I have only been writing perl for a few months, so forgive 
> me if this
> sounds stupid.

No, it's an excellent question.

> 
> what is the difference between:
> 
> $| = 1;
> and
> $|++;

The first assigns the value 1 to the variable $|
The second increments (adds 1 to) the current value of $|

$| is a "special" variable to Perl. It controls the automatic flushing of
output filehandles after a print(). The default is 0, which means no
auto-flush. Setting it to 1 (or any non-zero value) enables the
auto-flushing.

Assuming these statements appeared at the top of the program, the effect
would be the same for each. I prefer the first form to the second, since it
is not dependent on what other code may or may not be doing to $| (i.e.
consider if $| were -1 prior to the increment).

> 
>Or can you point me in the right direction on where I can read
> boutit?

perldoc perlvar
   explains the "special" variables like $|

perldoc perlop
   explains the operators like ++

HTH

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




Re: newbie question about Sys::Hostname and modules in general

2002-08-02 Thread drieux


On Friday, August 2, 2002, at 08:09 , Chad Kellerman wrote:
[..]
> ** I always have issues with scope  Can I use Sys::Hostname  just in
> the subroutine, or any perl module for that matter?  Or do I have to use
> it globally?
>
> $host=hostname; finds that daggone hostname and I have hostname all over
> te placemy bad.  :^(.
[..]


there are two strategies I hear you are asking about:

a) the difference between 'use v. require'
b) the scoping of variables


plan A:

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

use Sys::Hostname

..

sub Freak_Out {

my $msg = shift;
.
my $host = hostname;

}

the 'use' of course is essentially 'require foo && import foo'
so we imported the function there - and might not remember where
we got that function from - especially if we did not annotate
it up at the top of the script.

so you might try
plan B:

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

.

sub Freak_Out {

my $msg = shift;
.
require Sys::Hostname;
my $host = Sys::Hostname::hostname();

}

and completely ISOLATE the fact that you are using
the hostname() function there.


Your Third strategy would be something on the order of say


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

use Sys::Hostname
my $host = hostname;

..

sub Freak_Out {
my ( $from_host, $msg ) = @_;

}

hence requiring the caller to define it.

What I personally would consider the worst of all possibles
in this is the 'leaking global gag':

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

use Sys::Hostname
my $host = hostname;

..

sub Freak_Out {
my ( $msg ) = @_;


Log($host, $msg);
...
}

where you USE the globally defined '$host' without passing
it into the function this type of 'side effect' gets
ugly the first time you try to re-use the function Freak_Out()
somewhere else and forget that you were using a global
variable by indirection.


HTH

ciao
drieux

---


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




Re: newbie question

2002-05-18 Thread drieux


On Saturday, May 18, 2002, at 05:09 , Beau E. Cox wrote:

> use strict;
>
> my $data = "Received 921MB 16764 3955 375  2.2%   1296  7.7%";
> @_ = $data =~ /\b(\d+)\b/g;
> print "$_\n" for (@_);# prints 16764 3955 375 2 2 1296 7 7
> print "$_[2]\n";  # prints your guy: 375
>
> Throw the "global" (g) on the RegEx and get the results into an array...


In general I am leary of the 'fast cut' - where we use
the @_ and $_[$index] tricks - probably because I am
concerned about the side effects should we have to handle
a signal interrupt in the process

but so far I have not been able to prove my point in code...
so my complements on this! a reasonably elegant solution
that avoids the need for temporary variables.


ciao
drieux

---


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




RE: newbie question

2002-05-18 Thread Beau E. Cox

Hi -

use strict;

my $data = "Received 921MB 16764 3955 375  2.2%   1296  7.7%";
@_ = $data =~ /\b(\d+)\b/g;
print "$_\n" for (@_);  # prints 16764 3955 375 2 2 1296 7 7
print "$_[2]\n";# prints your guy: 375

Throw the "global" (g) on the RegEx and get the results into an array...

Aloha - Beau.

-Original Message-
From: Stuart Clark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, May 18, 2002 1:48 AM
To: Perl List
Subject: newbie question


Hi again,

Thanks john for helping me with this solution to get the 16764 out of
the $data string

($recievedmail) = $data =~ /\b(\d+)\b/;

I have another question 

How would I pick out the 375 in the same string

$data = "Received 921MB 16764 3955 375  2.2%   1296  7.7%";






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




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




RE: newbie question

2002-03-25 Thread Timothy Johnson


checkout perlre or do a search on regular expressions

-Original Message-
From: wahlstros [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 25, 2002 1:04 PM
To: John W. Krahn
Cc: [EMAIL PROTECTED]
Subject: Re: newbie question


where can i find a decent man page for understanding string pattern matching


>>push @phone, /\s(\d+\s\d+\s\d+):/;




- Original Message -
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 25, 2002 2:53 PM
Subject: Re: newbie question


> Anidil Rajendran-Raj wrote:
> >
> > Firstname Lastname 650 156 7190:somfield:somefield:somefield
> > Firstname Lastname 408 256 7290:somfield:somefield:somefield
> > Firstname Lastname 510 3456 7390:somfield:somefield:somefield
> >
> > I have the above lines in a file and I am trying to create an array of =
> > phone numbers
> >
> > open (FILE,"thefile") or die;
>
> You should include the file name and the $! variable in the error
> message.
>
> > @array =3D ;
>  ^^^
> This is not a valid operator
>
> > my @phone;
> > for each $string (@array) {
>   
> each() works with hashes, not scalars, you want to use my() here
>
> >   $phone[$i] =3D ($string =3D~ /\s\d+\s\d+\s\d+:/) ;
>^^^  ^^^
> Again, this is not a valid operator.
>
> >   $i++;
> > }
> >
> > This  does not work, what am I doing wrong? or it there a better way?
>
>
> open FILE, 'thefile' or die "Cannot open 'thefile': $!";
> my @phone;
> while (  ) {
> push @phone, /\s(\d+\s\d+\s\d+):/;
> }
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


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




This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

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




Re: newbie question

2002-03-25 Thread wahlstros

where can i find a decent man page for understanding string pattern matching


>>push @phone, /\s(\d+\s\d+\s\d+):/;




- Original Message -
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 25, 2002 2:53 PM
Subject: Re: newbie question


> Anidil Rajendran-Raj wrote:
> >
> > Firstname Lastname 650 156 7190:somfield:somefield:somefield
> > Firstname Lastname 408 256 7290:somfield:somefield:somefield
> > Firstname Lastname 510 3456 7390:somfield:somefield:somefield
> >
> > I have the above lines in a file and I am trying to create an array of =
> > phone numbers
> >
> > open (FILE,"thefile") or die;
>
> You should include the file name and the $! variable in the error
> message.
>
> > @array =3D ;
>  ^^^
> This is not a valid operator
>
> > my @phone;
> > for each $string (@array) {
>   
> each() works with hashes, not scalars, you want to use my() here
>
> >   $phone[$i] =3D ($string =3D~ /\s\d+\s\d+\s\d+:/) ;
>^^^  ^^^
> Again, this is not a valid operator.
>
> >   $i++;
> > }
> >
> > This  does not work, what am I doing wrong? or it there a better way?
>
>
> open FILE, 'thefile' or die "Cannot open 'thefile': $!";
> my @phone;
> while (  ) {
> push @phone, /\s(\d+\s\d+\s\d+):/;
> }
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


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




Re: newbie question

2002-03-25 Thread John W. Krahn

Anidil Rajendran-Raj wrote:
> 
> Firstname Lastname 650 156 7190:somfield:somefield:somefield
> Firstname Lastname 408 256 7290:somfield:somefield:somefield
> Firstname Lastname 510 3456 7390:somfield:somefield:somefield
> 
> I have the above lines in a file and I am trying to create an array of =
> phone numbers
> 
> open (FILE,"thefile") or die;

You should include the file name and the $! variable in the error
message.

> @array =3D ;
 ^^^
This is not a valid operator

> my @phone;
> for each $string (@array) {
  
each() works with hashes, not scalars, you want to use my() here

>   $phone[$i] =3D ($string =3D~ /\s\d+\s\d+\s\d+:/) ;
   ^^^  ^^^
Again, this is not a valid operator.

>   $i++;
> }
> 
> This  does not work, what am I doing wrong? or it there a better way?


open FILE, 'thefile' or die "Cannot open 'thefile': $!";
my @phone;
while (  ) {
push @phone, /\s(\d+\s\d+\s\d+):/;
}



John
-- 
use Perl;
program
fulfillment

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




RE: newbie question

2002-03-25 Thread Wagner-David

Here is a slightly modified version:

#!perl -w
use strict;

my @array = ;   # use DATA so don't have to play with file
my @phone;  
my $MyErrors = 0;  # let me know if errors
foreach (@array) {
  chomp; # remove linefeed
  next if ( /^\s*$/ ); # if blank line bypass
  if (/\s+(\d{3})\s+(\d{3})\s+(\d{4}):/ )  { # assuming std format of 3 3 4 and each 
line should   # have one
 push(@phone, $1 . ' ' . $2 . ' ' . $3 ); # just push on and add a space between
   }else {
 printf "Expecting a phone number in line, but did not find one in\n";
 printf "correct format.\nData received follows:\n%-s\n", $_;
 $MyErrors++
   }
}
if ( $MyErrors ) {
   printf "There were errors in processing. Please check and rerun\n";
 }
__DATA__
Firstname Lastname 650 156 7190:somfield:somefield:somefield
Firstname Lastname 408 256 7290:somfield:somefield:somefield
Firstname Lastname 510 3456 7390:somfield:somefield:somefield
^- Script ends here

Wags ;)


-Original Message-
From: Anidil Rajendran-Raj [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 25, 2002 11:46
To: [EMAIL PROTECTED]
Subject: newbie question


Firstname Lastname 650 156 7190:somfield:somefield:somefield
Firstname Lastname 408 256 7290:somfield:somefield:somefield
Firstname Lastname 510 3456 7390:somfield:somefield:somefield

I have the above lines in a file and I am trying to create an array of =
phone numbers

open (FILE,"thefile") or die;
@array =3D ;
my @phone;
for each $string (@array) {
  $phone[$i] =3D ($string =3D~ /\s\d+\s\d+\s\d+:/) ;
  $i++;
}

This  does not work, what am I doing wrong? or it there a better way?

Thanks



raj
[EMAIL PROTECTED]
650.730.8271



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

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




RE: Newbie Question

2002-03-11 Thread Hanson, Robert

Some versions of PPM had some problems, and your config file might have been
messed up.  I haven't seen this problem lately, but I have had it happen to
myself a while ago.

There should be a file called ppm.xml in your Perl library.  You will need
to check it out, and see if it is still a well-formed XML file.  ...Or if
you are not familiar with XML you may need to send it to the list if you can
(as an attachment probably).

If you have IE 5 you can chack it really quick by opening it is your
browser, if there is a problem it will tell you so.

But then again it could be something else.

Rob

-Original Message-
From: Eric Wang [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 11, 2002 3:21 PM
To: [EMAIL PROTECTED]
Subject: Newbie Question


Hi guys,
 
I have a newbie question.  I've tried to update my module packages and
was using ppm on win2k.  After I installed Tk, my ppm isn't working
anymore.  It'll still give me command prompt, but when I type verify
-upgrade, nothing happens.  Can anybody help me?  
 
Thanks
 
Eric

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




  1   2   >