Re: selecting select as an option was Re: first steps with perl, alog reader

2003-11-17 Thread R. Joseph Newton
Jeff 'japhy' Pinyan wrote:

> On Nov 16, R. Joseph Newton said:
>
> >sometimes.  The perfect setup for the great Perl anonymous block:
> >
> >{
> >$| = 1;
> > do  stuff that really needs to be autoflushed
> >}  # Get things back to normal
>
> I think you want a 'local' in front of that $| line.
>
>   {
> local $| = 1;
> # ...
>   }

Yep.  Thanks for the correction.

Joseph


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



Re: Perl Equavlent

2003-11-17 Thread R. Joseph Newton
Mike Blezien wrote:

> Hi,
>
> So if I use the int() this will provide the same results as this ceil() function
>   does... ??

Nope.  Same as floor().  If you want to round, use:
my $rounded = int ($float_value + 0.5);

Joseph


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



Re: File upload script

2003-11-17 Thread perl
I'm trying to allow users to upload their own webpages. I have both binary
and text format. Although, its probably ok to upload the webpages in
binary mode and it would bother the webserver.

In any case, I'm wondering if use CGI is the package to use and if there
is a cpan module that someone can recommend?

thanks

> --As off Sunday, November 16, 2003 5:17 PM -0800, [EMAIL PROTECTED]
> is alleged to have said:
>
>> Can someone point the way to some file upload script for webserver
>> on unix/linux?
>
> --As for the rest, it is mine.
>
> Single file, batch, automated, manual, FTP, RCP, email, SCP, CVS,
> SFTP, remote, local, web-based, commandline, GUI, from Windows, from
> Mac, from UNIX?
>
> Please, what is the problem you are trying to solve, and what have
> you tried?  Google only turns up around 167,000 hits for a search
> relating to this.  A little smaller problem-space would be useful...
>
> Daniel T. Staal
>
> ---
> This email copyright the author.  Unless otherwise noted, you
> are expressly allowed to retransmit, quote, or otherwise use
> the contents for non-commercial purposes.  This copyright will
> expire 5 years after the author's death, or in 30 years,
> whichever is longer, unless such a period is in excess of
> local copyright law.
> ---
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-
eMail solutions by 
http://www.swanmail.com

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



Capture a range from a mp3 track ?

2003-11-17 Thread Bee
I am trying to write a script which plays a range (input) from a mp3 file.

Simply to say, a mp3 file is divided into 3 session, Audio data, audio header,
and IDvX tags.

What I will deal with my script is to get the bit rate from the header, and calc
the start-end position of the data from the audio data, after this, I will have to 
modify the header, so to reform the complete "file", and then to play it as an 
embedded media with html.

But I have no idea on how to start with it while I am dealing with is binary 
data... Any approach could lead me to start ?

Thanks a lot





Re: Logging to a Server via ftp.

2003-11-17 Thread Yupapa.com
Hello~



#!/usr/bin/perl
use Net::FTP;
use strict;

my $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect
to some.host.name: $@";

$ftp->login("anonymous",'-anonymous@') or die "Cannot login ",
$ftp->message;
$ftp->quit;

__END__



Look at CPAN for more methods
http://search.cpan.org/~gbarr/libnet-1.17/Net/FTP.pm


Yupapa~
###
# Yupapa Web Hosting =^.^=
# Web Site - http://www.yupapa.com
# Support - http://forums.yupapa.com
# Email - [EMAIL PROTECTED]
###
"John" <[EMAIL PROTECTED]> ???:[EMAIL PROTECTED]
> Yes, logging into.
>
> Have you got a relevant script?
>
>
> - Original Message -
> From: "Wiggins d'Anconia" <[EMAIL PROTECTED]>
> To: "John" <[EMAIL PROTECTED]>
> Cc: "Perl Beginners" <[EMAIL PROTECTED]>
> Sent: Sunday, November 16, 2003 5:28 PM
> Subject: Re: Logging to a Server via ftp.
>
>
> > John wrote:
> > > What is the module and some examples to do tha bove job?
> > >
> > > Thanks in advance.
> >
> > I am assuming you mean "Logging into a server via ftp"...
> >
> > Net::FTP
> >
> > Or did you really mean "Logging to a server via ftp"...
> >
> > http://danconia.org
> >
>



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



beginners oops module

2003-11-17 Thread km
Hi all,
i wanna look at the (source code of) modules which give  a basic understanding of  
OOPS programming style in Perl. any pointers will be helpful .
thanks,
KM




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



RE: An Alternative to Test::Harness was Re: external sub routine

2003-11-17 Thread Rajesh Dorairajan
Forgive me for not making myself clear in the first place. What I'm trying
to do is create a Test framework for a server-class product that validates
digital certificates using Perl. I've a driver script that reads
configuration variables from an XML file using XML::Simple and execute a
bunch of tests on the server based on pre-set configuration variables. My
effort is to build an optimal, extensible test-suite, whereby I'll develop a
reasonably generic framework to which others (developers) can contribute
tests in future. This framework will also allow me to execute some tests and
skip others based on my requirements. The need to "pass variables" mainly
arises because I build relative paths to various directories in my
configuration file and the test scripts will need these values based on the
tests executed. One approach would be initialize all these values into
environment variables in my driver script. But this did not appeal to me as
an optimal approach. Can you share your ideas on this approach?

I have written Perl modules, which export specific functions. These
functions will be called from my test scripts based on the test-case being
executed. I also use standard CPAN-modules such as LWP and OpenCA::OpenSSL
in my test-suite. 

That said, the issue I'm facing is to create atomic test scripts that'll be
executed by my driver script based on some configuration file (such as
MANIFEST). These atomic scripts will import functions (and variables) from
the modules I've created and also from standard CPAN-modules as and when
necessary. I am looking for a mechanism whereby I can integrate these test
scripts with my driver program. Right now I've this huge driver program
where the tests are executed in sequence. To this extent I tried resuing the
capability already available in Test::Harness (instead of re-inventing the
wheel). But as Wiggins mentioned in an earlier mail, Test::Harness does not
allow variables to be "exported" to test scripts. So, I'm trying to find a
mechanism to overcome this problem. 

Hope I gave a better picture. Till now I've been going around in circles and
getting frustrated in the process. So, I decided to seek help from Perl
experts such as you :) I am trying to find out how I can go about
architecting the whole thing.

Thanks a lot for your valuable feedback. I am going through the test scripts
of LWP too.

Best Regds

Rajesh Dorairajan

-Original Message-
From: drieux [mailto:[EMAIL PROTECTED]
Sent: Friday, November 14, 2003 3:54 PM
To: begin begin
Subject: An Alternative to Test::Harness was Re: external sub routine



On Friday, Nov 14, 2003, at 13:59 US/Pacific, Rajesh Dorairajan wrote:
[..]
>  All I want to do is:
>
> #Create a logger object and log a message using log4perl
> #call the function and check the $retval
> #if $retval == 1 $logger->info("Test succeded")
> #else $logger->warn( "Test failed" )
>
> I've a bunch of such scenarios and I wish to have them in files
> like 0.t, 1.t, 2.t
[..]
>  As you can gather I am building a Test suite using
> Perl and would like to reuse mechanism used to test perl modules.
> In short I want to do something like:
>
> #main.pl
>
> #loop through MANIFEST and read contents into @tests
> #runtests from @tests
>
> #0.t
> sub test1 {
>  my ( $foo ) = shift;
>  #initialize logger object
>  #call a function from module bar::somebar
>  #if success log success
>  #if failure log failure
> }
>
> The key requirement is that the .t files must capable of acquiring 
> values
> from main.pl. Is this possible?

This is an interesting approach, forgive me if I need
a bit more information on how you are looking at the
issues of what is being passed into your test harness.

what I gather so far is that you have a directory with
the basics in it

Makefile.PL
Somebar.pm
MANIFEST
t/
0.t...

Traditionally when I am doing static code coverage
of that Somebar.pm { one should use at least one
capital in the Module Name, since all lower case
is reserved for pragma. } with the usual

perl Makefile.PL
make test

Or when you are talking about testing a perl module
is there some other context I am not seeing here

I am thinking in terms of having named files in
the t/ that deal with specific code cases, eg:

t/exception.t

would deal with checking the list of all of the
'exceptions' that it should be handled gracefully.
This way I actually put all of the information in there
that needs to be tested. IF I add a new function/method
and need to check that it will manage all 'n' new exception
cases I merely update that file with 'n' new specific cases.

The files in the t/ directory then become the 'configuration'
information as well as the executable.

I'm not sure that I see what 'value' is added by trying
to make those tests more 'dynamic' by reading from one
file and passing in additional information to the test
that will then test the Module in that directory.

So my problem is 

Re: Logging to a Server via ftp.

2003-11-17 Thread John
Thanks a lot Yupapa.com!


- Original Message -
From: "Yupapa.com" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 16, 2003 11:18 PM
Subject: Re: Logging to a Server via ftp.


> Hello~
>
>

> 
> #!/usr/bin/perl
> use Net::FTP;
> use strict;
>
> my $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot
connect
> to some.host.name: $@";
>
> $ftp->login("anonymous",'-anonymous@') or die "Cannot login ",
> $ftp->message;
> $ftp->quit;
>
> __END__
>

> 
>
> Look at CPAN for more methods
> http://search.cpan.org/~gbarr/libnet-1.17/Net/FTP.pm
>
>
> Yupapa~
> ###
> # Yupapa Web Hosting =^.^=
> # Web Site - http://www.yupapa.com
> # Support - http://forums.yupapa.com
> # Email - [EMAIL PROTECTED]
> ###
> "John" <[EMAIL PROTECTED]>
???:[EMAIL PROTECTED]
> > Yes, logging into.
> >
> > Have you got a relevant script?
> >
> >
> > - Original Message -
> > From: "Wiggins d'Anconia" <[EMAIL PROTECTED]>
> > To: "John" <[EMAIL PROTECTED]>
> > Cc: "Perl Beginners" <[EMAIL PROTECTED]>
> > Sent: Sunday, November 16, 2003 5:28 PM
> > Subject: Re: Logging to a Server via ftp.
> >
> >
> > > John wrote:
> > > > What is the module and some examples to do tha bove job?
> > > >
> > > > Thanks in advance.
> > >
> > > I am assuming you mean "Logging into a server via ftp"...
> > >
> > > Net::FTP
> > >
> > > Or did you really mean "Logging to a server via ftp"...
> > >
> > > http://danconia.org
> > >
> >
>
>
>
> --
> 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: first steps with perl, a log reader

2003-11-17 Thread Guardian Angel
On Mon, 2003-11-17 at 06:19, R. Joseph Newton wrote:
> Guardian Angel wrote:

> > But now... i want to be more precise with my script.
> > So i made 2 extra if loops, 1 is looking for errors, and if so, also
> > check if there is no 127.0.0.x adres in it anymore (works so far :D)
> 

> Whoa!  This is not the way to get a programming job done.  Rambling does not get you 
> there.
> Before you can write effective code, you have to focus your thinking process.  Don't 
> get
> caught up in fascination with coding tricks.  Look for tools to accomplish clearly 
> defined
> purposes.  Express those purposes, and the steps to achieve them, in plain language.
> 
> Most important, take a breath.
> 
> Joseph
> 
Uhm... lol... i get it. But this *is* working (although it will not be
the best code you ever seen ;))
Ofcourse i can better make a complete plan of what i want, but that is
too much atm.
I have *no* experience with coding at all, and it's a bit overwhelming
for now :) ( a lot of statements, loops, array's, hashes etc)
So i was just trying to make my scripts step by step more difficult, so
i can understand *why* Perl is doing things, and what it is doing.
That way i can better understand what happends, and then (ofcourse) I
have to find out exactly what i want, and how i want it... but for now
that is too much.
So i prefer little parts (which i can understand) and then step by step
learning more.
ie. i see a lot of ppl who start with (for me) heavy scripts (used with
2 or 3 modules) while they have not really a clue of what they are
doing... copy/ paste will work, but it will definitly not *learn* to
write code yourself :D
And now i will take a deep breath.aaahh (nice)

I've putted my last reply here, since it was only send to Joseph (by
accident), and not to the mailinglist.

On Sun, 2003-11-16 at 16:52, Rob Dixon wrote:
> Hi Sander. First of all, I guess this will feel like I'm ripping
> your code apart. Try to imagine me as your best-friend
> cardboard-cutout programmer with nothing but your interests
> at heart. :)

I'll do my best to see you as my best-friend, while you strip my 1st
code ;)
But thanx (also to the pther ppl) for pointing me to some things.


> Few people know what to make of Perl the first time they see
> it. People try to force it into either C or shell, but it's
> neither. Take a look at what I've written below, and keep an
> open mind!
> 
It's hard to start (as always), but it will work...some day :)
I have some knowledge about the shell and linux, but i don't write code
in any other language, so it's all new to me.


> 
>   use strict;   # Always
>   use warnings; # Usually (same as -w qualifier but portable)

i will do that, "use warnings;" gave me more (human readable) errors, so
better to understand for me.

I was looking for the > and < operators. I had used them with backticks
(but gave a error message, because it was a "greater then" value,
because i left spaces like print $a > $b instead of print $a>$b  
But now... i want to be more precise with my script.
So i made 2 extra if loops, 1 is looking for errors, and if so, also
check if there is no 127.0.0.x adres in it anymore (works so far :D)
then i want to sort the ip's and that's what dazzling me now...
This is what i want: I Look in the (newly) written error.log, and see
immediatley that someone with ip 123.45.6.7 has tried 1x to login. But
123.45.6.8 has tried to login 50x in the last 6 days... 
Now my thought was that i made an array to put everything from while
, and when it's an error message and *not* 127.0.0.x in the array,
then sort, and put it in the error.log unfortunatly it's not
working so i looked for the subroutines in Learning Perl... but i
don't get it *how* you can get these values

Thanx a lot

Sander 


#!/usr/bin/perl
use strict;
use warnings;
open (ER, ">/home/unicorn/Plscripts/error.log") || die "can't open EL,
$!\n"; #opening ERROR.LOG for Write

while () {  #as long as ER is open, read
   if (/error/)  {  #if there is any errormessage in the file
if (!/127.0.0.*/) {  #and it's not local 127.0.0.x
@sorted_list = sort by_ip (ER) ;#the inputfile
is sorted by ip in
@sorted_list
print EL $_;#print output to ERROR.LOG #was
print EL $_;
}
}
}
#sub by_ip {
#   @sorted_list = sort { $a <=> $b } EL;
#   }


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



Re: beginners oops module

2003-11-17 Thread Tore Aursand
On Mon, 17 Nov 2003 12:46:08 +0100, Tore Aursand wrote:
>> i wanna look at the (source code of) modules which give  a basic
>> understanding of  OOPS programming style in Perl. any pointers will be
>> helpful .

> Pointers to what?  Just take a look at come of the OO modules/classes
> out there, if you want to.  I would rather point you to a part of the
> Perl documentation relating to OO:
> 
>   perldoc perlobj
>   perldoc perltoot
>   perldoc perltooc

And - of course:

  perldoc perlboot


-- 
Tore Aursand <[EMAIL PROTECTED]>


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



Re: File upload script

2003-11-17 Thread Tore Aursand
On Mon, 17 Nov 2003 01:08:46 -0800, perl wrote:
> In any case, I'm wondering if use CGI is the package to use [...]

Why don't you bother finding out?  'perldoc CGI'.  Search for 'upload'.


-- 
Tore Aursand <[EMAIL PROTECTED]>


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



Re: Perl Equavlent

2003-11-17 Thread Tore Aursand
On Sun, 16 Nov 2003 23:24:29 -0800, R. Joseph Newton wrote:
> If you want to round, use:
> my $rounded = int ($float_value + 0.5);

...which only works if you have a positive number.  You must make it a bit
more foolproof;

  my $rounded = ($nr > 0) ? int($nr + 0.5) : int($nr - 0.5);


-- 
Tore Aursand <[EMAIL PROTECTED]>


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



Re: beginners oops module

2003-11-17 Thread Tore Aursand
On Mon, 17 Nov 2003 16:43:55 +0530, km wrote:
> i wanna look at the (source code of) modules which give  a basic
> understanding of  OOPS programming style in Perl. any pointers will be
> helpful .

Pointers to what?  Just take a look at come of the OO modules/classes out
there, if you want to.  I would rather point you to a part of the Perl
documentation relating to OO:

  perldoc perlobj
  perldoc perltoot
  perldoc perltooc


-- 
Tore Aursand <[EMAIL PROTECTED]>


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



RE: beginners oops module

2003-11-17 Thread NYIMI Jose (BMB)
ch3 of "Object Oriented Perl" book by Conway is free at
http://www.manning.com/getpage.html?project=conway&filename=Chapters.html

Great reads !

José.
-Original Message-
From: km [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 17, 2003 12:14 PM
To: [EMAIL PROTECTED]
Subject: beginners oops module


Hi all,
i wanna look at the (source code of) modules which give  a basic understanding of  
OOPS programming style in Perl. any pointers will be helpful . thanks, KM




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



 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


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



Re: beginners oops module

2003-11-17 Thread James Edward Gray II
On Nov 17, 2003, at 7:47 AM, NYIMI Jose (BMB) wrote:

ch3 of "Object Oriented Perl" book by Conway is free at
http://www.manning.com/getpage.html? 
project=conway&filename=Chapters.html

Great reads !
The rest of the book is excellent as well.  I recommend it.

James

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


Re: Perl Equavlent

2003-11-17 Thread James Edward Gray II
On Nov 17, 2003, at 1:24 AM, R. Joseph Newton wrote:

Mike Blezien wrote:

So if I use the int() this will provide the same results as this 
ceil() function
  does... ??
Nope.  Same as floor().  If you want to round, use:
my $rounded = int ($float_value + 0.5);
Please read the rest of the thread before adding to it.  This was 
covered in several messages four days ago.

int() != floor()

James

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


Re: text replacement+

2003-11-17 Thread James Edward Gray II
On Nov 16, 2003, at 10:22 PM, R. Joseph Newton wrote:

Kiko Uehara wrote:

If my question doesn't have enough information, please let me know.
Sure doesn't.  The most important information concerning any program is
what real-world purpose [even if simulated] it serves.  The coding 
comes
later.
I'm not sure I understand the new trend on this list to tell everyone 
they're not providing enough information.  Two solutions were posted 
before these complaints.  I know beginners often "simplify" what they 
think is the problem and make it hard if not impossible to help them, 
but I felt Kiko provided a lot of useful information.  How many posters 
leave out the data file completely?  I think we should be careful about 
which behaviors we are discouraging.

James

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


While or For

2003-11-17 Thread angie ahl
Hi list

I keep getting hung up on deciding whether to use for or while for
loops.

Is one any better than other for straight forward loops, ie where you
don't need next or last.

Cheers

Angie

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



When MUST you use 'map' ?

2003-11-17 Thread Jeff Westman
Hi,

In my limited experience with perl, I've never had to use the 'amp' command,
even though I see it used all the time.  It seems to just be a short-cut of
other commands/keywords that I've used.

So, when do you HAVE to use 'map', when no other option makes sense?!


-Jeff

__
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

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



Re: selecting select as an option was Re: first steps with perl, a log reader

2003-11-17 Thread drieux
On Sunday, Nov 16, 2003, at 21:22 US/Pacific, R. Joseph Newton wrote:

drieux wrote:

I on the other hand have had the unpleasantry of FORGETTING
that I was whacking new code in that was doing a 'select'.
So one solution is to make sure that IF you do a select that
you put things back where you found them, eg:
my $oldfh = select($newfh);
# the neat new stuff here
...
select($oldfh);
...or better yet, to redo your code a little, and write to and read
from explicitly-selected filehandles.
why?

ciao
drieux
---

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


Re: When MUST you use 'map' ?

2003-11-17 Thread Gaurav Kumar Somani

wat does amp do??

On Mon, 17 Nov 2003, Jeff Westman wrote:

> Hi,
> 
> In my limited experience with perl, I've never had to use the 'amp' command,
> even though I see it used all the time.  It seems to just be a short-cut of
> other commands/keywords that I've used.
> 
> So, when do you HAVE to use 'map', when no other option makes sense?!
> 
> 
> -Jeff
> 
> __
> Do you Yahoo!?
> Protect your identity with Yahoo! Mail AddressGuard
> http://antispam.yahoo.com/whatsnewfree
> 
> 

-- 
Thinking is the Capital,
Enterprise is the Way,
Hardwork is the Solution.


Gaurav Kumar Somani
200201086
NBH 129



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



Re: When MUST you use 'map' ?

2003-11-17 Thread drieux
On Monday, Nov 17, 2003, at 07:37 US/Pacific, Jeff Westman wrote:
[..]
In my limited experience with perl, I've never had to use
the 'amp' command, even though I see it used all the time.
It seems to just be a short-cut of other commands/keywords that I've 
used.

So, when do you HAVE to use 'map', when no other option makes sense?!
[..]

in terms of 'have to' - the answer is 'never',
since as the documentation "perldoc -f map"
notes, it is a 'cool way' to do
%hash = ();
foreach $_ (@array) {
$hash{getkey($_)} = $_;
}
where the 'getkey()' is some function that solves what
the key for that hash should be given the input...
One place that we all use it is in the Schwartzian Transformation:
cf

Yes, you could write that longer, but, well, there is a
sense of elan and elegance in it that is 'cool'.
So the real trade off is whether you need the 'verbosity'
of writing out the longer form to make your code clear
for the person coming along behind you to maintain it.
Or is it the sort of problem that needs something a bit
different from the standard grep tricks.
ciao
drieux
---

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


RE: When MUST you use 'map' ?

2003-11-17 Thread Charles K. Clarkson
Jeff Westman <[EMAIL PROTECTED]> wrote:
: 
: In my limited experience with perl, I've never had to use
: the 'map' command, even though I see it used all the time.
: It seems to just be a short-cut of other commands/keywords
: that I've used.
: 
: So, when do you HAVE to use 'map', when no other option
: makes sense?!

You never *have* to use map. It is a shortcut and it
and it can both obfuscate code and make it easier to read.
It depends on when you use it. The Schwartzian Transform
(a sorting solution) is much more readable using map. It
also can reduce the number of variables an algorithm uses.


Here's an example: map changes this

my @sales_figures = 1 .. 10;
foreach my $figure ( @sales_figures ) {
$figure = sprintf "\$% 3s.00\n", $figure;
}


To this:

@sales_figures = map { sprintf "\$% 3s.00\n", $_ } @sales_figures;

Beauty is in the eye of the beholder.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328









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



Re: While or For

2003-11-17 Thread Jeff 'japhy' Pinyan
On Nov 17, angie ahl said:

>I keep getting hung up on deciding whether to use for or while for
>loops.

Well, it usually depends on how the code "reads".  I use 'while' for loops
based on a condition that will change in some execution of the block.

  while () {
# eventually,  will return undef when the file is exhausted
  }

  while ($i < 5) {
# $i will be changed somehow
# eventually it will be greater than or equal to 5
  }

  while ($x or $y or $z) {
# continue while one of those three variables is still true
  }

It's important to note that

  while () { ... }

is identical to

  while (defined($_ = )) { ... }

which only reads ONE line at a time, whereas

  for () { ... }

reads ALL the lines of the file at once, into a list.

A for loop is best used for iterating over a list of values, or, in the
C-style loop, running through a range.

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


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



Re: While or For

2003-11-17 Thread drieux
On Monday, Nov 17, 2003, at 09:04 US/Pacific, Jeff 'japhy' Pinyan wrote:
[..]
which only reads ONE line at a time, whereas

  for () { ... }

reads ALL the lines of the file at once, into a list.
really good point there.

but wouldn't the position been just a tad stronger
had you noted that the above is similar to
	my @file_lines = ;

and that the traditional

	 while () { ... }

form is used so as not to require all of the memory
that would come from 'sucking in the whole file' to an array.
so a simple general rule would be that the 'for' and
in particular the
foreach my $token (@list)
{
	}

construct is a good list iterator,
while 'while' is for not just list iterating...
not a great mneomic, it does have some irony in it.

ciao
drieux
---

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


Dynamic Hash

2003-11-17 Thread Kent, Mr. John

Greetings,

Am using perl to dynamically write some JavaScript code
that creates cool drop down button menus by Ger Versluis found
on http://www.dynamicdrive.com  ( for those who want to 
know why).


Have a directory structure in which the target files are located
at various levels of sub-directories.

Trying to create a dynamically sized hash of unknown dimensions
where each sub directory name is a dimension of the hash and it
gets assigned the file.

For example
my(%HASH);
$HASH{$sub1}{$sub2}{$sub3} = $file1;
$HASH{$sub1}{$sub2}{$sub3}{$sub4}{$sub5} = $file2;


Here is what I tried, unsuccessfully

no strict 'refs'

# @TERMS is an array of each sub-directory name up to the one containing the target 
file

my(%NAV_HASH);
   # Build the multi-dimensional hash
 my($hash_string) = "NAV_HASH";
 foreach my $sub_dir (@TERMS){
 $hash_string .= "{\"$sub_dir\"}";
 }
 print "hash_string = $hash_string\n" if ($DEBUG == 1);  # <- This looks 
good
 # Producing a hash_string = 
NAV_HASH{"Africa"}{"focus_regions"}{"OEF_Somalia"}{"Overview"}{"high_low_cloud"}

 # Now turn this string into a real hash and
 # assign it a value
 $$hash_string = "$last,";

Afterwards running this shows I've accomplished nothing
if ($DEBUG == 1){
print "Here is the NAV_HASH:\n";
foreach (keys(%{$$hash_string})){
print "$_ => $$hash_string{$_}}\n";
}
}

$$hash_string is NOT a hash.  <-- Herein lies the problem as Billy Zardell would say

Thank you for any assistance,
John Kent



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



r/w files

2003-11-17 Thread km
Hi all,

I have a doubt in File handling concept. 
right now i am using such code : 

--snippet-start---
open my $h,$filename or die  $!;
# do something here  --- 
close $h;
snippet-end--

Is there any other efficient way while dealing with r/w operations on files > 200MB ? 

thanks,
KM


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



Re: Starting Perl

2003-11-17 Thread Randal L. Schwartz
> "R" == R Joseph Newton <[EMAIL PROTECTED]> writes:

R>   I totally forgot, by the time I got to addressing .pm, that
R> extensions in any context could be other than Evil in Randal's
R> universe.

See, I never ever said that.  Odd how I would get misheard on this
point.

Extensions for *commands* typed by the *user* to indicate something
that the user doesn't care about is evil.  Other uses of extensions
are perfectly fine.

-- 
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: Dynamic Hash

2003-11-17 Thread drieux
On Monday, Nov 17, 2003, at 08:48 US/Pacific, Kent, Mr. John wrote:
[..]
For example
my(%HASH);
$HASH{$sub1}{$sub2}{$sub3} = $file1;
$HASH{$sub1}{$sub2}{$sub3}{$sub4}{$sub5} = $file2;
Here is what I tried, unsuccessfully

no strict 'refs'

# @TERMS is an array of each sub-directory name up to the one 
containing the target file

my(%NAV_HASH);
[..]
$$hash_string is NOT a hash.  <-- Herein lies the problem as Billy 
Zardell would say
quite right, you had declared it to
be a static string:
	my($hash_string) = "NAV_HASH";

whereas

	my $hash = {};

would have been a reference to a hash...

and you really do NOT want to be playing any of the
"dynamic variables" gambiting that would lead that way.
You might want to think about a slightly more complex
data structure to help you deal with your problem, if
I even get your problem... so let me see if I can
write out the file system layout that would wind up
in your hash
/sub1/sub2/sub3/file1.html
/sub1/sub2/sub3/sub4/sub5/file2.html
What I am trying to figure out is what the data
is 'suppose to be' at say
	$hash->{'sub1'}

What I expect you were seeing with

	print "hash_string = $hash_string\n" if ($DEBUG == 1);  # <- This 
looks good

would be something like

	NAV_HASH{sub1}{sub2}{sub3}

So while I am so not sure that I get why you want
to do this tree traversal this way, what if you tried
something like,
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
# #FILENAME# - is for

my $file_1 = '/sub1/sub2/sub3/file1.html';
my $file_2 = '/sub1/sub2/sub3/sub4/sub5/file2.html';
my $ref = {};
hang_sub($ref, $file_1);
hang_sub($ref, $file_2);
print Dumper($ref);

#
#
sub hang_sub
{
my ($hash, $file ) = @_;

my $next = $hash;
my $parent;
my @TERMS =  split('/', $file);
my $target = pop @TERMS;

my $sub_dir;
foreach $sub_dir (@TERMS) {
$next->{$sub_dir} ={}
unless(exists($next->{$sub_dir}));

$parent = $next->{$sub_dir};
$next = $next->{$sub_dir};
}

my $key = keys %$parent;
$parent->{'file'} = $target;

} # end of hang_sub
Data::Dumper can be your friend

ciao
drieux
---

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


[ADMIN] Re: File upload script

2003-11-17 Thread Casey West
It was Monday, November 17, 2003 when Tore Aursand took the soap box, saying:
: On Mon, 17 Nov 2003 01:08:46 -0800, perl wrote:
: > In any case, I'm wondering if use CGI is the package to use [...]
: 
: Why don't you bother finding out?  'perldoc CGI'.  Search for 'upload'.

This isn't a proper response.  Please try to be more helpful.  We're
here to be extra helpful.  He's trying to find out, and it's possible
he just doesn't know where to look.

In this case, he's way off.  He's talking about FTP, and most likely
wants to look at Net::FTP.

  http://search.cpan.org/perldoc?Net::FTP

  Casey West

-- 
f u cn rd ths, u cn gt a gd jb n cmptr prgmmng.


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



Failed Test lib/odbm.t

2003-11-17 Thread Saskia van der Elst
Hi,

I am in the process of installing perl-5.6.2 on my SuSE Linux 8.1 machine. 

After running 'make install' and ./perl harness, one test fails: lib/odbm.t

How do I make Perl pass this test?

Thanks,

SvdE


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



pagination of dbi results on html browser

2003-11-17 Thread A L
Hi Everyone at [EMAIL PROTECTED],
Threre are two main questions:
1. How can I get to make results from mysql db to be displayed on web browser with 
pagination?  Meaning, when there are too many results from the db, it only displays 20 
results at a time-like that of google-and show links to rest of the results by giving 
page numbers.  I've used Data::Page module from CPAN, but I can only get it to print 
out the result to the web statically without giving links to other pages and all the 
results are still displayed on one page when there should be 33 pages or more (the 
total pages number changes as more stuff are added to the db).  Also, DBIx::Pager from 
CPAN was looked (I'm still working on it to work), but it doesn't seem like it is not 
going to do what I'm expecting.  Am I looking at the right places?  If not, will you 
tell me what I should be looking at?
 
2.  I'm trying to creat the select all button and deselect all button in one button.  
Meaning, when I click on the button, it selects all the checkboxes displayed  and 
turns to deselect all button; when I click on the button, again, with all the check 
boxes checked, I uncheck all the boxes and return the button to select all button.  
When I search for this on the web, most of them give javascript results.  I would like 
to use Perl.  Is it possible to do this with Perl?  If so, what should I be looking 
at?  At CPAN, only thing that results is toc and cgi where I couldn't get what I'm 
looking for?  Have I not looked carefully and missed something?
 
Okay, I'm not sure if I should insert my codes here because I haven't yet tried 
something that would do what I want to do.  But, if you think that will help you 
understand my questions better, I will do so.  Thanks for your time.
 
Angela


-
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Re: pagination of dbi results on html browser

2003-11-17 Thread Casey West
It was Monday, November 17, 2003 when A L took the soap box, saying:
: Hi Everyone at [EMAIL PROTECTED], Threre are two main questions:
: 1. How can I get to make results from mysql db to be displayed on web
:browser with pagination? Meaning, when there are too many results
:from the db, it only displays 20 results at a time-like that of
:google-and show links to rest of the results by giving page
:numbers. I've used Data::Page module from CPAN, but I can only get
:it to print out the result to the web statically without giving
:links to other pages and all the results are still displayed on
:one page when there should be 33 pages or more (the total pages
:number changes as more stuff are added to the db). Also,
:DBIx::Pager from CPAN was looked (I'm still working on it to
:work), but it doesn't seem like it is not going to do what I'm
:expecting. Am I looking at the right places? If not, will you tell
:me what I should be looking at?

You're not too far off. I'd suggest looking at Class::DBI,
Class::DBI::mysql, and Class::DBI::Pager. They should help a lot.

: 2.  I'm trying to creat the select all button and deselect all button
: in one button. Meaning, when I click on the button, it selects all
: the checkboxes displayed and turns to deselect all button; when I
: click on the button, again, with all the check boxes checked, I
: uncheck all the boxes and return the button to select all button.
: When I search for this on the web, most of them give javascript
: results. I would like to use Perl. Is it possible to do this with
: Perl? If so, what should I be looking at? At CPAN, only thing that
: results is toc and cgi where I couldn't get what I'm looking for?
: Have I not looked carefully and missed something?

Client side, you want Javascript.

If you really want to cluge through a request to the webserver, you'll
have to deal with CGI's param()s to do what you want.

  Casey West

-- 
There are two major products that come out of Berkeley: LSD and
UNIX. We don't believe this to be a coincidence. 
 -- Jeremy S. Anderson


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



Re: Failed Test lib/odbm.t

2003-11-17 Thread drieux
On Monday, Nov 17, 2003, at 12:33 US/Pacific, Saskia van der Elst wrote:
[..]
I am in the process of installing perl-5.6.2 on my SuSE Linux 8.1 
machine.

After running 'make install' and ./perl harness, one test fails: 
lib/odbm.t
well it would help if we knew what
the 'failure' message was.
	make test

would walk you through it. And do you really mean
perl-5.6.2 or did you mean perl-5.8 ???
If you are not going with the perl-5.8, why
not see if you can get it to build, or is
this a backwards compatability additional build???
ciao
drieux
---

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


RE: pagination of dbi results on html browser

2003-11-17 Thread Guay Jean-Sébastien
Hello A L,


> When I search for this on the web, most of them give javascript results.
I would like > to use Perl.  Is it possible to do this with Perl?

Why would you want to do something like that in Perl? When you click a
button on a web form, the only time you want to call a server-side script is
when actually submitting the form (some exceptions of course). For something
like that, which is basically interface convenience, you want fast
interaction (i.e. you don't want to wait for a web page to load, which is
what doing this server-side will entail). In a case like this, do it with
JavaScript.

Of course, you will have to make your Perl script that generates the page
generate the JavaScript so that it will check/uncheck as many items as you
really have (if those items are variable, generated by your script). In that
case, a templating mechanism (HTML::Template, Template::Toolkit, etc) will
help greatly, with the added benefit of separating code and interface, which
will make your Perl/web project easier to maintain.

Hope that helps. Good luck,

J-S

_
Jean-Sébastien Guay
-- Conseiller technique - Administration
-- (514) 522-9800 #4840
-- [EMAIL PROTECTED]

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



matching

2003-11-17 Thread Eric Walker
I have the following code to find a quote in a string and replace it
with a slashquote.

ie " goes to \"  

How do I get it to do more than one substitution in the string.


$_ = $$Rules{$yes}{rule_desc};
s/"/\\"/;
$$Rules{$yes}{rule_desc} = $_;

newbie...


Re: matching

2003-11-17 Thread James Edward Gray II
On Nov 17, 2003, at 4:18 PM, Eric Walker wrote:

I have the following code to find a quote in a string and replace it
with a slashquote.
ie " goes to \"

How do I get it to do more than one substitution in the string.
The /g modifier, for "global".

$_ = $$Rules{$yes}{rule_desc};
s/"/\\"/;
$$Rules{$yes}{rule_desc} = $_;
Let's clean that up a little.  We don't need $_ here.

$$Rules{$yes}{rule_desc} =~ s/"/\\"/g;

How's that?

James

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


Is it possible to send / receive cookies on an image

2003-11-17 Thread Dan Anderson
Is it possible to create a perl script that would send to the user an
image and cookies.  Depending on the cookie on the users computer, the
user would get a certain picture. 

I figure I would have to use CGI, but what else, if anything, would I
need to do?

Thanks in advance,

-Dan


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



Re: pagination of dbi results on html browser

2003-11-17 Thread Jeff 'japhy' Pinyan
On Nov 17, A L said:

>1. How can I get to make results from mysql db to be displayed on web
>browser with pagination?  Meaning, when there are too many results from
>the db, it only displays 20 results at a time-like that of google-and
>show links to rest of the results by giving page numbers.  I've used
>Data::Page module from CPAN, but I can only get it to print out the
>result to the web statically without giving links to other pages and all
>the results are still displayed on one page when there should be 33 pages
>or more (the total pages number changes as more stuff are added to the
>db).  Also, DBIx::Pager from CPAN was looked (I'm still working on it to
>work), but it doesn't seem like it is not going to do what I'm expecting.
>Am I looking at the right places?  If not, will you tell me what I should
>be looking at?

The way I've done this is:

  use DBI;
  use CGI 'param';

  my $dbh = DBI->connect($dsn, $username, $password, { RaiseError => 1 });
  my $offset = param('offset') || 0;
  my $limit = 10;
  my ($prev, $next) = ($offset - $limit, $offset + $limit);
  $prev = 0 if $prev < 0;

  my $query = qq{ SELECT * FROM table WHERE f=? LIMIT $offset, $limit };
  my $n_query = qq{ SELECT * FROM table WHERE f=? LIMIT $next, 1 };
  my $arg = param('arg');

  my $sth = $dbh->prepare($query);
  $sth->execute($arg);

  while (my $rec = $sth->fetchrow_hashref) {
# do stuff with $rec
  }

  $sth = $dbh->prepare($n_query);
  $sth->execute($arg);

  # if this is not the FIRST set of records
  print qq{<<<}
if $prev != $offset;

  # if there are more rows to show after these
  print qq{>>>}
if $sth->rows;

I expect that's more or less what DBIx::Pager does, but I've never used
the module.

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



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



Re: matching

2003-11-17 Thread Eric Walker
Thanks that worked



On Mon, 2003-11-17 at 15:27, James Edward Gray II wrote:

On Nov 17, 2003, at 4:18 PM, Eric Walker wrote:

> I have the following code to find a quote in a string and replace it
> with a slashquote.
>
> ie " goes to \"
>
> How do I get it to do more than one substitution in the string.

The /g modifier, for "global".

> $_ = $$Rules{$yes}{rule_desc};
> s/"/\\"/;
> $$Rules{$yes}{rule_desc} = $_;

Let's clean that up a little.  We don't need $_ here.

$$Rules{$yes}{rule_desc} =~ s/"/\\"/g;

How's that?

James




Re: Is it possible to send / receive cookies on an image

2003-11-17 Thread drieux
On Monday, Nov 17, 2003, at 14:33 US/Pacific, Dan Anderson wrote:

Is it possible to create a perl script that would send to the user an
image and cookies.  Depending on the cookie on the users computer, the
user would get a certain picture.
I figure I would have to use CGI, but what else, if anything, would I
need to do?
since you are about to stumble into the land of

	[EMAIL PROTECTED]

yes, they too have a mailing list.

My recommendations on reading material for CGI work is at:

Most of them you will just want to buy, and curl up with
in bed until you understand all of the DOM's, and the oddities
of HTML, javascript, etc.
A part of what you will ultimately want to feel at home with
is mostly in the CGI.pm module - but you might want to
deal with things like:

which I have merely played around with.
if you have the time, play around with

	

Hope that Helps.

ciao
drieux
---

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


Re: pagination of dbi results on html browser

2003-11-17 Thread A L
Thanks so much for all your help!  I'll look into it and let you how things turn out.
Angela



-
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

the Scripting v. Coding Issue

2003-11-17 Thread drieux
volks,

someone asked me off list some questions,
and one that makes me giggle is this still,
for me, fallacious distinction about the
differences between scripting and coding.
So I have put that rant up as:



Hopefully it will help clarify why when I see
a 'simple' question, I may move just a tad beyond
the 'directly asked' - if for no other reason than
to help folks along the line from 'wrote a script'
to 'maintain some code'
enjoy.

ciao
drieux
---

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


Failed Test lib/odbm.t

2003-11-17 Thread Saskia van der Elst
The problem:

Failed Test Stat Wstat Total Fail  Failed  List of Failed
---
lib/odbm.t   127 32512??   ??   %  ??
14 tests and 226 subtests skipped.
Failed 1/375 test scripts, 99.73% okay. 0/15092 subtests failed, 100.00% okay.

was solved by doing:

make distclean
rm -f config.sh Policy.sh

sh Configure -Ui_dbm

I interrupted the manual configuration process by appending &-d to one of the 
answers.

make test (this time all tests were passed)
make install

My problem was probably caused by the fact that I had eliminated the perl-5.6 
version that my Linux vendor had provided me with, in order to install 
perl-5.8.

BTW, it was in the INSTALL.txt:

Here are the
Configure command-line variables you can set to turn off various
extensions.  All others are included by default.

DB_File i_db
DynaLoader  (Must always be included as a static extension)
GDBM_File   i_gdbm
NDBM_File   i_ndbm
ODBM_File   i_dbm
POSIX   useposix
Opcode  useopcode
Socket  d_socket
Threads use5005threads

Thus to skip the NDBM_File extension, you can use

sh Configure -Ui_ndbm

Again, this is taken care of automatically if you don't have the ndbm
library.

Of course, you may always run Configure interactively and select only
the extensions you want.


Drieux, thanks for your help!

Saskia

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



Re: Failed Test lib/odbm.t

2003-11-17 Thread drieux
On Monday, Nov 17, 2003, at 17:51 US/Pacific, Saskia van der Elst wrote:
[..]
Drieux, thanks for your help!

Saskia
Stylish, I have never had to throw the '-U'
and always configured them the old fashion way
by answering all the questins
all of which is ironic since good perlers
of course know how to build out perl to run it,
and it is not written in perl Hum.
ciao
drieux
---

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


Re: matching

2003-11-17 Thread Tore Aursand
On Mon, 17 Nov 2003 15:18:47 -0700, Eric Walker wrote:
> How do I get it to do more than one substitution in the string.

By using the /g modifier.

> $_ = $$Rules{$yes}{rule_desc};

No.  Don't _ever_ try to set $_ yourself, unless you _really_ have to
(which you don't in this case).

> $_ = $$Rules{$yes}{rule_desc};
> s/"/\\"/;
> $$Rules{$yes}{rule_desc} = $_;

These three lines could easily have been shortened down to only one;

  $$Rules{$yes}{rule_desc} =~ s/"/\\"/g;

However:  Why do you need to quote the " characters?


-- 
Tore Aursand <[EMAIL PROTECTED]>


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



Re: first steps with perl, a log reader

2003-11-17 Thread R. Joseph Newton
Guardian Angel wrote:

> On Mon, 2003-11-17 at 06:19, R. Joseph Newton wrote:
> > Guardian Angel wrote:
>
> > > But now... i want to be more precise with my script.
> > > So i made 2 extra if loops, 1 is looking for errors, and if so, also
> > > check if there is no 127.0.0.x adres in it anymore (works so far :D)
> >
>
> > Whoa!  This is not the way to get a programming job done.  Rambling does not get 
> > you there.
> > Before you can write effective code, you have to focus your thinking process.  
> > Don't get
> > caught up in fascination with coding tricks.  Look for tools to accomplish clearly 
> > defined
> > purposes.  Express those purposes, and the steps to achieve them, in plain 
> > language.
> >
> > Most important, take a breath.
> >
> > Joseph
> >
> Uhm... lol... i get it. But this *is* working (although it will not be
> the best code you ever seen ;))
> Ofcourse i can better make a complete plan of what i want, but that is
> too much atm.
> I have *no* experience with coding at all, and it's a bit overwhelming
> for now :) ( a lot of statements, loops, array's, hashes etc)
> So i was just trying to make my scripts step by step more difficult, so
> i can understand *why* Perl is doing things, and what it is doing.
> That way i can better understand what happends, and then (ofcourse) I
> have to find out exactly what i want, and how i want it... but for now
> that is too much.

Sounds good.  It is good to stretch yourself, too, but the trick is to keep track of 
the process
while you are doing it.  Break things down into manageable chinks.  This is really the 
core of
effective programming IMHO.  It is also fine to take a while working with simple 
programs.  Many
of the programming tasks needed are fairly straightforward.

>
> So i prefer little parts (which i can understand) and then step by step
> learning more.
> ie. i see a lot of ppl who start with (for me) heavy scripts (used with
> 2 or 3 modules) while they have not really a clue of what they are
> doing... copy/ paste will work, but it will definitly not *learn* to
> write code yourself :D

That can be alright too, if it helps you get started.  My first Perl script, back in 
2000,, was
an adaptation of Matt's Guestbook script.  I dinked with it a bit to use a hidden 
field in the
submission form to specify a target page to put the code at the bottom of.  The 
original scrit
was for a single page that was all guestbook.  My adaptations worked, and it was 
pretty cool.

There were soe problems with this, too.  For something like a week, I was stuck on a 
blind system
error (since I didn't have a compiler at home to test my code on.  It turns out that I 
was trying
to access a hash element with parens.  the text editor I was using didn't show the 
distinction
clearly, and it wasn't until I pasted the code into my C++ IDE that I could even see 
the
difference.  Had I written smaller programs of my own earlier, I am sure this woudl 
not have
escaped me.

> And now i will take a deep breath.aaahh (nice)

Great!  That and maybe taking a walk can often be just the ticket for unlocking sticky
programming issues.

Joseph


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



Re: When MUST you use 'map' ?

2003-11-17 Thread R. Joseph Newton
Jeff Westman wrote:

> Hi,
>
> In my limited experience with perl, I've never had to use the 'amp' command,
> even though I see it used all the time.  It seems to just be a short-cut of
> other commands/keywords that I've used.
>
> So, when do you HAVE to use 'map', when no other option makes sense?!
>

When you want to preserve an array, but generate a second one based on some
function of each element.

Greetings! E:\d_drive\ocf\discuss\prototype>perl -w
my @source = (3, 6, 7, 9);
my @target = map $_ + 1, @source;
print "$_ " for @source;
print "\n";
print "$_ " for @target;
print "\n";
^Z
3 6 7 9
4 7 8 10

It should ot be used to modify the elements in the original. You are right--that
is what a for() loop is for.  You should be careful to avoid processes that
affect the default variable, because they can have evil side-effects:

Greetings! E:\d_drive\ocf\discuss\prototype>perl -w
my @source = (3, 6, 7, 9);
my @target = map ++$_, @source;
print "$_ " for @source;
print "\n";
print "$_ " for @target;
print "\n";
^Z
4 7 8 10
4 7 8 10

...or worse.  That was actually my second try at illustrating the problem.  The
first, using the more familiar postfix increment, had even more horrid results:

Greetings! E:\d_drive\ocf\discuss\prototype>perl -w
my @source = (3, 6, 7, 9);
my @target = map $_++, @source;
print "$_ " for @source;
print "\n";
print "$_ " for @target;
print "\n";
^Z
4 7 8 10
3 6 7 9

... as in, the completely wrong array got changed. Tthere are many good uses for
mappings, I can assure you.  They just should not be used for their side effects

Joseph


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