Re: Extracting links. - without modules

2005-01-17 Thread Alexander Blüm
On Sun, 16 Jan 2005 18:36:09 +0500
Sara [EMAIL PROTECTED] wrote:

 I am trying to extract links along with HTML tags a href=blah from a
 list, but it's not working on my XP machine with Active State Perl
 5.0.6 Kindly help.
 
 # CODE START 
 
 my @array = qq|
 bodya href=http://www.mydomain.com;img alt=Free Hosting,
 Freebies border=0
 src=http://www.mydomain.com/images/logo2.gif;/a|;#extract LINKS
 (no image links) only a href=http://www.mydomain.com;
 
 my @get = grep {/a .*?/} @array;
 print @get\n
 
 ### CODE END ###
 
 Thanks,
 
 Sara.
 

this is also possible _without_ any modules, except maybe strict.

# this will replace the contents of each match in @get
foreach(@array){
  my @get = $_ =~ /a href=(.*?)/g;
}

or: 

# this will add each match to @get
my @get = ();
foreach(@array){
  push @get, $_ =~ /a href=(.*?)/g;
}


-- 
Cheers,
  Alex

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




Re: Insecure dependency in glob while running with -T switch

2005-01-17 Thread Paul Archer
I just tried that on the command-line, and I'm not getting the warning 
you're seeing. What version of Perl are you running?
And have you tried alternatives like
my @files = `ls`;

or using opendir/readdir?
Paul
Yesterday, David Gilden wrote:
Last question here,
#!/usr/bin/perl -wT
 Snip ...
my @filesToRemove = *;
The line above is causing:
Insecure dependency in glob while running with -T switch
What can I do still have this functionally and satisfy 'tainting'
Thanks,
Dave
tel: 817-741-2327 fax: 972-916-3451
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response

-
Welcome to downtown Coolsville--population: us.
-
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Extracting links. - without modules

2005-01-17 Thread Chris Devers
On Mon, 17 Jan 2005, Alexander Blüm wrote:

 this is also possible _without_ any modules, except maybe strict.
 
 # this will replace the contents of each match in @get
 foreach(@array){
   my @get = $_ =~ /a href=(.*?)/g;
 }

What happens if the url has a doublequote followed by an angle bracket?

It's not likely, but it can happen, and it can work.

And if such a URL is discovered, this regex would break.

What happens if the url isn't wrapped in quotes at all?

This is much more likely, and again will work fine in browsers.

But again, this regex won't find it at all.

This kind of problem is why HTML (and XML) is really best processed 
using pre-written parser modules, such as HTML::SimpleLinkExtor. A 
parser has a much better shot at getting a proper view of the document 
than a simple regex pattern match.

Yes, you can approach such problems using simple regular expressions, 
such as what we have here, and in many cases they'll work, and maybe 
even work faster than the parser version would. On the other hand, this 
approach is much less generally robust: minor changes that don't break 
the HTML may break the regex, so you end up having to constantly adjust 
it to handle all the special cases that come up over time. 

If you just parse it at the outset, such as with HTML::SimpleLinkExtor, 
then the code should be simple, robust, and useful for a long time.

 
 

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


perl.beginners.cgi Weekly list FAQ posting

2005-01-17 Thread casey
NAME
beginners-faq - FAQ for the beginners-cgi mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?
Send mail to [EMAIL PROTECTED]

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

[EMAIL PROTECTED].

  1.2 -  How do I unsubscribe?
Now, why would you want to do that? Send mail to
[EMAIL PROTECTED], and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

[EMAIL PROTECTED]

  1.3 - There is too much traffic on this list. Is there a digest?
Yes. To subscribe to the digest version of this list send an email to:

[EMAIL PROTECTED]

To unsubscribe from the digest, send an email to:

[EMAIL PROTECTED]

  1.4 - Is there an archive on the web?
Yes, there is. It is located at:

http://archive.develooper.com/beginners-cgi%40perl.org/

  1.5 - How can I get this FAQ?
This document will be emailed to the list once a month, and will be
available online in the archives, and at http://beginners.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?
Send an email to [EMAIL PROTECTED] with your suggestion.

  1.7 - Is there a supporting website for this list?
Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who do I complain to?
Complaints can be sent to [EMAIL PROTECTED]

  1.9 - Who currently maintains the FAQ?
Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?
Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl/CGI beginners.

  1.11 - When was this FAQ last updated?
Feb 04, 2004

2 -  Questions about the 'beginners-cgi' list.
  2.1 - What is the list for?
A list for beginning Perl programmers to ask questions in a friendly
atmosphere. The topic of the list is, of course, CGI with Perl.

  2.2 - What is this list _not_ for?
* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Non Perl/CGI questions or issues
* Lemurs

  2.3 - Are there any rules?
Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun

  2.4 - What topics are allowed on this list?
Basically, if it has to do with Perl/CGI , then it is allowed. If your
question has nothing at all to do with Perl/CGI, it will likely be
ignored.

  2.5 - I want to help, what should I do?
Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?
We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?
Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

perldoc perldoc

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

3 - Other Resources
  3.1 - What other websites may be useful to a beginner ?
* Perl.org - http://www.perl.org
* Perl Home Page - http://www.perl.com
* PerlMonks - http://www.perlmonks.org
* Perldoc - http://www.perldoc.com
* Perl Archives - http://www.perlarchives.com
* NMS Archive - http://nms-cgi.sourceforge.net/
* Unofficial Perl Beginners' Site - http://perl-begin.berlios.de

  3.2 - What resources may be harmful to a beginner?
Beware of Perl4-like code-- You might find some script archives and
unauthorized mirrors with old Perl4 versions of Selena Sol and Matt
Wright scripts. Don't use those scripts. They are outdated and may even
in some cases 

RE: Insecure dependency in glob ... with -T switch

2005-01-17 Thread David Gilden
Hi,
The code below works fine if run like:

using PERL version 5.00503


#!/usr/bin/perl -w

but with
#!/usr/bin/perl -wT 

I am still getting error: Insecure dependency in glob while running with -T 
switch

Can I turn off 'tainting' for this block 

{
# turn off taint for this block only

opendir(DR,./);
my @filesToRemove  =  grep  {$_ =~ /^(\w[\w.-]*)/} readdir DR;
closedir DR;

foreach my $fr (@filesToRemove) {

print  Deleting $frbr\n;
unlink($fr)  or die Couldn't Delete $fr $!;
}

}


Is there anyway around this, I can't upgrade the version of PERL it out my 
hands.
Thx,

Dave

(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

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




Can;t locate the module

2005-01-17 Thread Anish Kumar K.
Hi I tried this Chart::ThreeD::Pie module. Installation doesn't show any error..
I am getting this error...
In the line 21, I have use GD;

How will I install this module.. please help me

Can't locate GD.pm in @INC (@INC contains: /usr/lib/perl5/5.6.0/i386-linux 
/usr/lib/perl5/5.6.0 /usr/lib/perl5/site_perl/5.6.0/i386-linux 
/usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl .) at 
/usr/lib/perl5/site_perl/5.6.0/Chart/ThreeD/Pie.pm line 21.

Thanks
Anish


Substitute Varaible

2005-01-17 Thread Anish Kumar K.
Hi I need help regarding substituion of varaibles with values

Say I have a txt file (a.txt)

which has only one line:
Hi $name

The PL file

open INPUT, a.txt;
my $name=Anish;
my $temp=;
while (INPUT)
{
  $temp=$temp.$_;
}
close(INPUT);
print Content is: $temp;

In the output I want the $name to get as Anish..O/P like Hi Anish






Re: Substitute Varaible

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 16:11:54 +0530, Anish Kumar K.
[EMAIL PROTECTED] wrote:
 Hi I need help regarding substituion of varaibles with values
 
 Say I have a txt file (a.txt)
 
 which has only one line:
 Hi $name

Don't think of $name as a perl variable, but as a placeholder. It
looks better if you use something like __NAME__. ie
Hi __NAME__

For substition, you simply use:
s/__NAME__/$var/;

Tor

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




XS problem.

2005-01-17 Thread Jesper Krogh
Hi. 

I'm trying to make perl bindings for the GnuTLS library, but I'm having
som problems with h2xs when generating XS-stubs:

$ h2xs -x /usr/include/gnutls/gnutls.
Defaulting to backwards compatibility with perl 5.8.4
If you intend this module to be compatible with earlier perl version
specify a minimum perl version with the -b option.

Writing Gnutls/ppport.h
Scanning typemaps...
 Scanning /usr/share/perl/5.8/ExtUtils/typemap
Scanning /usr/include/gnutls/gnutls.h for functions...
panic: multiple types without intervening comma in
 struct gnutls_session_int* gnutls_session
whited-out as
gnutls_session_int* gnutls_session
panic: multiple types without intervening comma in
 struct gnutls_dh_params_int* gnutls_dh_params
whited-out as
gnutls_dh_params_int* gnutls_dh_params
panic: multiple types without intervening comma in
 struct gnutls_rsa_params_int* gnutls_rsa_params
whited-out as
gnutls_rsa_params_int* gnutls_rsa_params
panic: multiple types without intervening comma in
 int (*gnutls_db_store_func)(void*, gnutls_datum key, gnutls
whited-out as
 (*gnutls_db_store_func)(void*,  key,   
panic: multiple types without intervening comma in
 int (*gnutls_db_remove_func)(void*, gnutls_datum key)
whited-out as
 (*gnutls_db_remove_func)(void*,  key)
panic: multiple types without intervening comma in
 gnutls_datum (*gnutls_db_retr_func)(void*, gnutls_datum key
whited-out as
  (*gnutls_db_retr_func)(void*,  key
panic: multiple types without intervening comma in
 struct DSTRUCT* gnutls_certificate_credentials
whited-out as
DSTRUCT* gnutls_certificate_credentials
panic: multiple types without intervening comma in
 struct DSTRUCT* gnutls_anon_server_credentials
whited-out as
DSTRUCT* gnutls_anon_server_credentials
panic: multiple types without intervening comma in
 struct DSTRUCT* gnutls_anon_client_credentials
whited-out as
DSTRUCT* gnutls_anon_client_credentials
panic: multiple types without intervening comma in
 struct gnutls_x509_privkey_int* gnutls_x509_privkey
whited-out as
gnutls_x509_privkey_int* gnutls_x509_privkey
panic: multiple types without intervening comma in
 struct gnutls_x509_crl_int* gnutls_x509_crl
whited-out as
gnutls_x509_crl_int* gnutls_x509_crl
panic: multiple types without intervening comma in
 struct gnutls_x509_crt_int* gnutls_x509_crt
whited-out as
gnutls_x509_crt_int* gnutls_x509_crt
panic: multiple types without intervening comma in
 void* (*gnutls_alloc_function)(size_t)
whited-out as
 void* (*gnutls_alloc_function)(size_t)
panic: multiple types without intervening comma in
 void* (*gnutls_calloc_function)(size_t, size_t)
whited-out as
 void* (*gnutls_calloc_function)(  )
panic: multiple types without intervening comma in
 void (*gnutls_free_function)(void*)
whited-out as
  (*gnutls_free_function)(void*)
panic: multiple types without intervening comma in
 void* (*gnutls_realloc_function)(void*, size_t)
whited-out as
 void* (*gnutls_realloc_function)(void*, size_t)
Expecting parenth after identifier in `fd_set *__restrict __readfds'
after `fd_set *__restrict ' at /usr/local/share/perl/5.8.4/C/Scan.pm


Am I taking a completely wrong approach to this? 

I have begun writing the XS-stubs myself but there are som ENUM's defined 
in the header it would be helpful if h2xs could help me to get access to. 

Jesper

-- 
./Jesper Krogh, [EMAIL PROTECTED]


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




Re: Can perl produce a huge-sized file for download testing?

2005-01-17 Thread Chris Devers
On Mon, 17 Jan 2005, Robin wrote:

 On Monday 17 January 2005 19:53, Harold Castro wrote:
  versa. What I'm thinking now is to create a simple
  perl script that will create a file, as huge as it can
  be, or just a continues stream of dummy bytes being
  uploaded to a remote host. Only I don't know where to
  begin. Any idea??

 I'd pull a long string of bytes from /dev/urandom (say, several 10s of 
 Kb worth) and just send that block over and over. (random so that you 
 get the information of the line without any interim compression 
 happening)

...and do a checksum on either end (md5, etc) to verify that what went 
across the wire is identical to what was originally generated.
 
 

-- 
Chris Devers

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




Re: Can perl produce a huge-sized file for download testing?

2005-01-17 Thread Gavin Henry
quote who=zentara
 On Sun, 16 Jan 2005 22:53:29 -0800 (PST), [EMAIL PROTECTED] (Harold
 Castro) wrote:

Hi,
   Our company is involved in internet service
providing, and as such, troubleshooting our partner's
links is one of our day to day activities. We have our
own network monitoring system using mrtg and other
stuffs. On some occasions with intermittent links, the
mrtg is not acting as accurate as we are specting it
to. We therefore need to test our links manually by
downloading huge files from host to host and vice
versa.

Sorry, but for ease, have you seen:

http://dast.nlanr.net/Projects/Iperf/#whatis

Server mode is excellent.

Gavin.

-- 
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

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




CGI.pm and form creation

2005-01-17 Thread Mauro
I'm trying to create a little form usign CGI.pm but I get this error from 
apache:
 malformed header from script. Bad header=form method=post action=/c: 
/usr/lib/cgi-bin/make_graph_CPU_form.pl.cgi

this is my perl code:

#!/usr/bin/perl
use CGI qw/:standard/;

sub print_form {
print start_form,
Metriche:,
 checkbox(-name='usr',-checked=1),
 checkbox(-name='sys',-checked=0),
 checkbox(-name='wio',-checked=0),
 checkbox(-name='idle',-checked=0),
 reset(-name='Reset'),
 submit(-name='Go!'),
 end_form;
};

print header,
start_html('RRDTool CPU Usage Monitor'),
h1('RRDTool CPU Usage Monitor'),
print_form(),
Nothing to it!\n,
end_html;

I don't understand why apache tells:action=/c: 
/usr/lib/cgi-bin/make_graph_CPU_form.pl.cgi when the form prints out form 
method=post action=/./make_graph_CPU_form.pl.cgi 
enctype=application/x-www-form-urlencoded
Could you help me?

Thank You


Mauro

Re: CGI.pm and form creation

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 14:41:40 +0100, Mauro [EMAIL PROTECTED] wrote:
 I'm trying to create a little form usign CGI.pm but I get this error from 
 apache:
  malformed header from script. Bad header=form method=post action=/c: 
 /usr/lib/cgi-bin/make_graph_CPU_form.pl.cgi
 
 this is my perl code:
 
 #!/usr/bin/perl
 use CGI qw/:standard/;
 
 sub print_form {
 print start_form,
 Metriche:,
  checkbox(-name='usr',-checked=1),
  checkbox(-name='sys',-checked=0),
  checkbox(-name='wio',-checked=0),
  checkbox(-name='idle',-checked=0),
  reset(-name='Reset'),
  submit(-name='Go!'),
  end_form;
 };
 
 print header,
 start_html('RRDTool CPU Usage Monitor'),
 h1('RRDTool CPU Usage Monitor'),
 print_form(),
 Nothing to it!\n,
 end_html;

Replace the above with:

## start headers
print header, start_html(foo), h1(bar);

print_form();

## end html
print end_html;

The problem is that print_form() is evaluated to early in the code or
something :)
 
Tor

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




RE: CGI.pm and form creation

2005-01-17 Thread Moon, John
I'm trying to create a little form usign CGI.pm but I get this error from
apache:
 malformed header from script. Bad header=form method=post action=/c:
/usr/lib/cgi-bin/make_graph_CPU_form.pl.cgi

this is my perl code:

#!/usr/bin/perl
use CGI qw/:standard/;

sub print_form {
print start_form,
Metriche:,
 checkbox(-name='usr',-checked=1),
 checkbox(-name='sys',-checked=0),
 checkbox(-name='wio',-checked=0),
 checkbox(-name='idle',-checked=0),
 reset(-name='Reset'),
 submit(-name='Go!'),
 end_form;
};

print header,
start_html('RRDTool CPU Usage Monitor'),
h1('RRDTool CPU Usage Monitor'),
print_form(),
Nothing to it!\n,
end_html;

I don't understand why apache tells:action=/c:
/usr/lib/cgi-bin/make_graph_CPU_form.pl.cgi when the form prints out form
method=post action=/./make_graph_CPU_form.pl.cgi
enctype=application/x-www-form-urlencoded
Could you help me?

Please replace :
snip 
sub print_form {
print start_form,
/snip

with 

snip

sub print_form {
return start_form,
/snip

...

You can also always see what you are generating by running the cgi script
from the commamd prompt... 

DEV,SUN2./foo.cgi
(offline mode: enter name=value pairs on standard input)
{reply ctrl+d}
Content-Type: text/html

!DOCTYPE HTML PUBLIC -//IETF//DTD HTML//EN
HTMLHEADTITLERRDTool CPU Usage Monitor/TITLE
/HEADBODYH1RRDTool CPU Usage Monitor/H1FORM METHOD=POST
ENCTYPE=application/x-www-form-urlencoded
Metriche:INPUT TYPE=checkbox NAME=usr VALUE=on CHECKEDusr
INPUT TYPE=checkbox NAME=sys VALUE=onsys
INPUT TYPE=checkbox NAME=wio VALUE=onwio
INPUT TYPE=checkbox NAME=idle VALUE=onidle
INPUT TYPE=reset VALUE=ResetINPUT TYPE=submit NAME=Go!
VALUE=Go!INPUT TYPE=hidden NAME=.cgifields VALUE=usrINPUT
TYPE=hidden NAME=.cgifields VALUE=idleINPUT TYPE=hidden
NAME=.cgifields VALUE=wioINPUT TYPE=hidden NAME=.cgifields
VALUE=sys/FORMNothing to it!
/BODY/HTMLDEV,SUN2



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




separating list alphabetically

2005-01-17 Thread Tim McGeary
I have some data that needs to be split up alphabetically into lists 
that start with each letter of the alphabet.  Sample data is like the 
following with real URL data in place of URL1 and URL2.  Only the first 
field is important for alphabetizing.  If I do an array with each letter 
(and it can be assumed that it will always start with a capital letter), 
how can I do something like the following?

foreach $letter (@alphabet) {
  if firstchar of $data = $letter {
push @{$letter}, $data
  }
}
sample data:
Psychology|URL1|URL2|
Notes and Queries|URL1|URL2|
ACM|URL1|URL2|
Biology|URL1|URL2|
Thanks,
Tim
--
Tim McGeary
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: separating list alphabetically

2005-01-17 Thread Bakken, Luke
 I have some data that needs to be split up alphabetically into lists 
 that start with each letter of the alphabet.  Sample data is like the 
 following with real URL data in place of URL1 and URL2.  Only 
 the first 
 field is important for alphabetizing.  If I do an array with 
 each letter 
 (and it can be assumed that it will always start with a 
 capital letter), 
 how can I do something like the following?
 
 foreach $letter (@alphabet) {
if firstchar of $data = $letter {
  push @{$letter}, $data
}
 }
 
 sample data:
 
 Psychology|URL1|URL2|
 Notes and Queries|URL1|URL2|
 ACM|URL1|URL2|
 Biology|URL1|URL2|

use strict;
use warnings;
use Data::Dumper;

my %data;
while(DATA)
{
chomp;
my ($str, @rest) = split /\|/;
# use 'lc substr...' if you want case
# insensitivity
my $letter = substr $str, 0, 1;
$data{$letter}{$str} = [EMAIL PROTECTED];
}
print Dumper(\%data);

__DATA__
Psychology|URL1|URL2|
Notes and Queries|URL1|URL2|
ACM|URL1|URL2|
Biology|URL1|URL2|

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




perl.beginners Weekly list FAQ posting

2005-01-17 Thread casey
NAME
beginners-faq - FAQ for the beginners mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?
Send mail to [EMAIL PROTECTED]

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

[EMAIL PROTECTED].

  1.2 -  How do I unsubscribe?
Now, why would you want to do that? Send mail to
[EMAIL PROTECTED], and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

[EMAIL PROTECTED]

  1.3 - There is too much traffic on this list. Is there a digest?
Yes. To subscribe to the digest version of this list send an email to:

[EMAIL PROTECTED]

To unsubscribe from the digest, send an email to:

[EMAIL PROTECTED]

This is a high traffic list (100+ messages per day), so please subscribe
in the way which is best for you.

  1.4 - Is there an archive on the web?
Yes, there is. It is located at:

http://archive.develooper.com/beginners%40perl.org/

  1.5 - How can I get this FAQ?
This document will be emailed to the list once a week, and will be
available online in the archives, and at http://learn.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?
Send an email to [EMAIL PROTECTED] with your suggestion.

  1.7 - Is there a supporting website for this list?
Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who do I complain to?
You can send complaints to [EMAIL PROTECTED]

  1.9 - Who currently maintains the FAQ?
Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?
Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl beginners.

  1.11 - When was this FAQ last updated?
Feb 04, 2004

2 -  Questions about the 'beginners' list.
  2.1 - What is the list for?
A list for beginning Perl programmers to ask questions in a friendly
atmosphere.

  2.2 - What is this list _not_ for?
* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Monkeys
* Monkeys solicitating homework on non-Perl related SPAM.

  2.3 - Are there any rules?
Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun

  2.4 - What topics are allowed on this list?
Basically, if it has to do with Perl, then it is allowed. You can ask
CGI, networking, syntax, style, etc... types of questions. If your
question has nothing at all to do with Perl, it will likely be ignored.
If it has anything to do with Perl, it will likely be answered.

  2.5 - I want to help, what should I do?
Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?
We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

Please do not quote the documentation unless you have something to add
to it. It is better to direct someone to the documentation so they
hopefully will read documentation above and beyond that which answers
their question. It also helps teach them how to use the documentation.

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?
Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

perldoc perldoc

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

  2.8 Is this a high traffic list?
YES! You have been warned! If you don't want to get ~100 emails per day
from this list, consider subscribing to the digest.

  2.9 Other tips before posting to the list
   

Counting occurences of a char in a line

2005-01-17 Thread Tor Hildrum
Hi,

I have the following code in a script I'm writing:

foreach my $line (INN) {
if ( 10 == ($line =~ s/,/,/g) ) {
print OUT $line;
}
}

Is this poor style? It looks a bit ugly, but I can't figure out a
better way to do it. I'm sure there is :)
The script will be reused and probably maintained by someone else. Is
there a more standard way of doing this?

regards

Tor

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




RE: Counting occurences of a char in a line

2005-01-17 Thread Bakken, Luke
 Hi,
 
 I have the following code in a script I'm writing:
 
 foreach my $line (INN) {
 if ( 10 == ($line =~ s/,/,/g) ) {
 print OUT $line;
 }
 }
 
 Is this poor style? It looks a bit ugly, but I can't figure out a
 better way to do it. I'm sure there is :)
 The script will be reused and probably maintained by someone else. Is
 there a more standard way of doing this?

for my $line (INN) {
if ( 10 == ($line =~ tr/,//) ) {
print OUT $line;
}
}

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




Re: Regex help

2005-01-17 Thread Dave Gray
On Mon, 17 Jan 2005 08:37:07 +0100, manfred [EMAIL PROTECTED] wrote:
 
 That leads me to a question :-)
 
   if ($num =~ /^(\d+)\#([^\#]*?)\#(?:e\+(\d+))?$/x) {
 
 What particular use has the _x_ modifier in this example?
 I mean the hashes are escaped?

I forgot to remove the /x when I stripped the comments from the regex
because if this was homework, I wanted the OP to work to understand it
;)

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




losing a value after chomp()

2005-01-17 Thread RichT
  Hi All,

   time for me to ask dumb questions again...

I have a script, what i want it to do is scan through a Cisco
router Config file (nicely saved in a text file already so no need for
and SNMP), then output it to a .csv file.
I an using the  Cisco::Reconfig; module to help me out.

  My problem is when i try to remove a charidge return from a
variable, the value ends up blank, you will see from below i have
tryed a few different ways to make this work, but i am lost (i suspect
some basic Perl knowledge is missing).
  any help would be most appreciated thank you .

cut down version of
Script---
#!/usr/local/bin/perl
use strict;
use Cisco::Reconfig;
use warnings;


# Scan  routers configs
# Parameters :
#   router name of site to be found
#   $router.cfg file : this is the data file
# Returns :
#   outputs a csv with port info from config

my($routerName)=$ARGV[0] || die  you must supply a router name on the
command line;
my($findVars)=discription, ip address, cctReff, siteName, vpnName;
my($findInterfaces)=Serial,POS,ATM;
my($interface);

if ( ! -r dir/$routerName.cfg) {die could not read
currIPS/$routerName.cfg : $!;}

my $config = readconfig(dir/$routerName.cfg);

for my $interfaceTypes (split/\,/,$findInterfaces) { #loop throught
interface types
  
  for my $found ($config-get('interface')-all($interfaceTypes)) { #
loop through found interfaces

$interface=getPortFromFullInterface($found) || die $!;
#chomp $interface;  -- i trtyed this 

print $interface\n;
  }
} #end for

sub getPortFromFullInterface {
#  chomp @_; -- i trtyed this 
  my $part=@_;

  $part =~ s/^interface //g;
  $part =~ s/ point-to-point//g;
  $part =~ s/ multipoint//g;
#  $part =~ s/\n$//g;-- i trtyed this 
  return($part);
};



/Script---

SampleData---

!
interface ATM0
 description ~atm0 ~ab_cdefg-r10-001 ~1/123 ~IS5B000 ~CBUK
~000
 bandwidth 288
 no ip address
 no atm ilmi-keepalive
 dsl operating-mode auto
no shutdown
!
interface ATM0.38 point-to-point
 description vpn ~cscngte_vpn1
 ip address 123.123.123.123 255.255.255.255
 pvc 0/38 
  oam-pvc manage
  oam retry 3 5 1
no shutdown
 !
\SampleData---
-- 
--
Fnord...
-- http://23.me.uk -- -- http://info-x.co.uk  -- --
http://wiki.seti23.org -- -- Get FireFox Now --

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




Re: Substitute Varaible

2005-01-17 Thread Dave Gray
On Mon, 17 Jan 2005 16:11:54 +0530, Anish Kumar K.
[EMAIL PROTECTED] wrote:
 Hi I need help regarding substituion of varaibles with values
 
 Say I have a txt file (a.txt)
 
 which has only one line:
 Hi $name
 
 The PL file
 

  use strict;
  use warnings;

 open INPUT, a.txt;

Always check the success of file opens!
  open INPUT, ' a.txt' or die couldn't read a.txt: $!\n;

 my $name=Anish;
 my $temp=;
 while (INPUT)
 {
   $temp=$temp.$_;

This could also be written as:
  $temp .= $_;
Personal preference, I guess.

 }
 close(INPUT);
 print Content is: $temp;
 
 In the output I want the $name to get as Anish..O/P like Hi Anish

Check out the eval built-in:
  close(INPUT);
  # evaluate the content of $temp as perl[1]
  # this won't work if there are any double quotes in $temp
  $temp = eval qq/$temp/;

There is probably a better way to do what you're trying to
accomplish... can you give us a bigger picture?

HTH,
Dave

[1] http://www.perldoc.com/perl5.8.4/pod/func/eval.html

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




Net::FTP and filehandle with get()

2005-01-17 Thread steve abrams
Hi all,
First post to the group. I have two questions, but they go hand in hand. The 
first:

Net::FTP documentation reports that get syntax is:
get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
I do the following (with $ftp initialization omitted here):
local $fh = IO::File-new_tmpfile;
$ftp-get($dump_path, $fh);
print $fh; (or print $fh;)
When I run this, I get no errors, but I can not get the text into the 
temporary file. I have also tried:

open(FILE,  anything.txt);
$ftp-get($dump_path, FILE);
Here, the file is created, but contains no text.
To show this works otheriwse, if I try:
$ftp-get($dump_path,  anything.txt);
sure enough, It works great.
What am I doing wrong in the first example?
Second question:
The following is from the get() subroutine in the FTP Perl Module:
$localfd = ref($local) || ref(\$local) eq GLOB
? fileno($local)
: undef;
($local = $remote) =~ s#^.*/##
   unless(defined $local);
where $local comes from:
my($ftp,$remote,$local,$where) = @_;
Could someone explain what this code is doing (several things happening here 
I havn't seen before, I was looking at this to see what was wrong with how I 
was using a filehandle.)

Thanks!
Steve

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



Re: losing a value after chomp()

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 17:57:28 +, RichT [EMAIL PROTECTED] wrote:
   Hi All,
 
time for me to ask dumb questions again...
 
 I have a script, what i want it to do is scan through a Cisco
 router Config file (nicely saved in a text file already so no need for
 and SNMP), then output it to a .csv file.
 I an using the  Cisco::Reconfig; module to help me out.
 
   My problem is when i try to remove a charidge return from a
 variable, the value ends up blank, you will see from below i have
 tryed a few different ways to make this work, but i am lost (i suspect
 some basic Perl knowledge is missing).
   any help would be most appreciated thank you .

chomp($var); is perfectly valid.

Try this code:

 sub getPortFromFullInterface {
   my $part = shift;

 print I'm inside getPortFromFullInterface(), \$part is: $part\n;
 
   $part =~ s/^interface //g;
   $part =~ s/ point-to-point//g;
   $part =~ s/ multipoint//g;
 chomp($part);

   return($part);
 };

Tor

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




Problem using CGI::Session

2005-01-17 Thread Octavian Rasnita
Hi all,

I have tried using the module CGI::Session with MySQL.

If I try
$session-id;

It prints fine the hash of the current session, but if I try to

print $session-name;
or
$session-header;

It gave me the following error:

Can't locate auto/CGI/Session/MySQL/name.al in @INC (@INC contains:
f:/web/presa/modules F:/usr/lib F:/usr/site/lib .) at
F:\web\presa\scripts\test.pl line 16

A short test script which gives those errors is:

use DBI;
use CGI;
use CGI::session;

my $q = CGI-new;
my $dbh = DBI-connect(DBI:mysql:database=presa;host=localhost, ODBC,
undef, {PrintError = 1, RaiseError = 1, AutoCommit = 1});

my $session = CGI::Session-new(driver:MySQL;id:MD5, undef,
{Handle=$dbh});

#The following line inserts fine this variable in a MySQL table
#$session-param('lala', 'lulu');

#This prints fine the session ID
#print $session-id;

#But this line gives an error
print $session-name;

#This line also prints the error below:
$session-header;

__END__

Can't locate auto/CGI/Session/MySQL/header.al in @INC (@INC contains:
F:/usr/lib F:/usr/site/lib .) at F:\web\presa\scripts\test.pl line 18

Help! I cannot see what could be wrong!

Thank you.

Teddy


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




Re: Forcing script to run as root?

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 14:08:10 -0500, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Worked perfectly. I knew it was something simple. Thanks!
 
 Never used POSIX before. Looked at it on cpan but those descriptions can be
 flat sometimes. If you don't mind, what are some practical uses for it? Just
 basic OS stuff?

Yes and No. OS-stuff, but not basic.
You probably need to be a C-programmer to really miss it :)

But, usually, Perl has it's own functions that are easier or better
to use.

http://www.perl.com/doc/manual/html/lib/POSIX.html

Tor

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




Re: Problem using CGI::Session

2005-01-17 Thread Octavian Rasnita
Hi again,

Sorry for my previous post.  I found the problem.

I wrote by mistake:

use CGI::session;

(with a small s and this sometimes work under Windows, but sometimes for
some tasks it doesn't.

And that's why perl didn't tell me that it couldn't find that module.

Teddy

- Original Message - 
From: Octavian Rasnita [EMAIL PROTECTED]
To: beginners@perl.org
Sent: luni, 17 ianuarie 2005 21:12 PM
Subject: Problem using CGI::Session


Hi all,

I have tried using the module CGI::Session with MySQL.

If I try
$session-id;

It prints fine the hash of the current session, but if I try to

print $session-name;
or
$session-header;

It gave me the following error:

Can't locate auto/CGI/Session/MySQL/name.al in @INC (@INC contains:
f:/web/presa/modules F:/usr/lib F:/usr/site/lib .) at
F:\web\presa\scripts\test.pl line 16

A short test script which gives those errors is:

use DBI;
use CGI;
use CGI::session;

my $q = CGI-new;
my $dbh = DBI-connect(DBI:mysql:database=presa;host=localhost, ODBC,
undef, {PrintError = 1, RaiseError = 1, AutoCommit = 1});

my $session = CGI::Session-new(driver:MySQL;id:MD5, undef,
{Handle=$dbh});

#The following line inserts fine this variable in a MySQL table
#$session-param('lala', 'lulu');

#This prints fine the session ID
#print $session-id;

#But this line gives an error
print $session-name;

#This line also prints the error below:
$session-header;

__END__

Can't locate auto/CGI/Session/MySQL/header.al in @INC (@INC contains:
F:/usr/lib F:/usr/site/lib .) at F:\web\presa\scripts\test.pl line 18

Help! I cannot see what could be wrong!

Thank you.

Teddy


-- 
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: Substitute Varaible

2005-01-17 Thread John W. Krahn
Anish Kumar K. wrote:
Hi I need help regarding substituion of varaibles with values
That is a Frequently Asked Question.
perldoc -q How can I expand variables in text strings

Say I have a txt file (a.txt)
which has only one line:
Hi $name
The PL file

open INPUT, a.txt;
You should *ALWAYS* verify that the file opened correctly.
open INPUT, '', 'a.txt' or die Cannot open 'a.txt' $!;

my $name=Anish;
my $temp=;
while (INPUT)
{
  $temp=$temp.$_;
}
The usual way to slurp the entire contents of a file is:
my $temp = do { local $/; INPUT };
Or you could use the File::Slurp module.

close(INPUT);
print Content is: $temp;
In the output I want the $name to get as Anish..O/P like Hi Anish

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



Re: separating list alphabetically

2005-01-17 Thread John W. Krahn
Tim McGeary wrote:
I have some data that needs to be split up alphabetically into lists 
that start with each letter of the alphabet.  Sample data is like the 
following with real URL data in place of URL1 and URL2.  Only the first 
field is important for alphabetizing.  If I do an array with each letter 
(and it can be assumed that it will always start with a capital letter), 
how can I do something like the following?
That is a Frequently Asked Question.
perldoc -q How can I use a variable as a variable name

foreach $letter (@alphabet) {
  if firstchar of $data = $letter {
push @{$letter}, $data
  }
}
sample data:
Psychology|URL1|URL2|
Notes and Queries|URL1|URL2|
ACM|URL1|URL2|
Biology|URL1|URL2|
It is probably better to use a hash:
my %data;
while ( DATA ) {
chomp;
my ( $letter ) = /([a-zA-Z])/;
push @{ $data{ $letter } }, $_;
}

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



Re: Counting occurences of a char in a line

2005-01-17 Thread John W. Krahn
Tor Hildrum wrote:
Hi,
Hello,
I have the following code in a script I'm writing:
foreach my $line (INN) {
if ( 10 == ($line =~ s/,/,/g) ) {
print OUT $line;
}
}
Is this poor style? It looks a bit ugly, but I can't figure out a
better way to do it. I'm sure there is :)
The script will be reused and probably maintained by someone else. Is
there a more standard way of doing this?
That is a Frequently Asked Question.
perldoc -q How can I count the number of occurrences of a substring within a 
string


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



regular expression question

2005-01-17 Thread Vincent
Hi all,

I am new to perl, I receive some spam email with subject like st0ck,
0pportunities, gr0wth..., how can I match those words with number 0 in

Thanks in advance

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




replacing multiple matches with an array

2005-01-17 Thread B McKee
Hi All
I have this bit of code in a program I'm working on.
 while (RAWREPORT) {
  next if /\f/ ;
  next if /^DATE : / ;
  next if /^\s{15,}PART / ;
  next if /^COUNTER QTY/ ;
  next if /^\s+$/  ;
  print ; # debugging purposes - other stuff here
}
It works, but I'd rather put all my patterns in an array so it's neat 
and tidy.
Something like

 my @possibleMatches = (\f,^DATE :,^\s{15,}PART ,^COUNTER 
QTY,^\s+$) ;
 while (RAWREPORT) {
  next if /@possibleMatches/
  print ; # debugging purposes - other stuff here
 }

but that doesn't work as is.  I could loop over the array I suppose and 
name each loop
something like [untested]

 my @possibleMatches = (\f,^DATE :,^\s{15,}PART ,^COUNTER 
QTY,^\s+$) ;
 OUTER:  while (RAWREPORT) {
  INNER:  foreach $my match (@possibleMatches) {
  next OUTER if /$match/
  print ; # debugging purposes - other stuff here
 }
but that doesn't seem much better to me.
Is there a common way to do this?
Comments appreciated
Brian

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



Re: regular expression question

2005-01-17 Thread Dave Gray
 I am new to perl, I receive some spam email with subject like st0ck,
 0pportunities, gr0wth..., how can I match those words with number 0 in

Something like

__CODE__
use warnings;
use strict;
use Data::Dumper;

# add to this hash to make it slower
my %rep = (
  'a' = [4],
  'e' = [3],
  'i' = [1, '!'],
  'o' = [0],
# etc
);
my @words = qw/stock opportunities growth/;
# this generates regular expressions
# you can use elsewhere
for my $word (@words) {
  $word =~ s/$_/'(?:'. join('|', @{$rep{$_}},$_) .')'/gei 
for keys %rep;
}

print Dumper([EMAIL PROTECTED]);
__END__

This will be very slow, though.

HTH,
Dave

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




Re: Forcing script to run as root?

2005-01-17 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
Hi all. How can I check, within a script, to see if it is being run as root
or not? I would like it to exit with an error message if it is not running
as root. I'm looking for something that works across *nix platforms so that
my script is portable. Is there a perl function that does this or perhaps
checking the uid?
 
I looked at the USER in %ENV but that does not show as root when I su to
root. At least, not in FreeBSD.
perldoc perlvar
[snip]
   $REAL_USER_ID
   $UID
   $  The real uid of this process.  (Mnemonic: it's the uid you came
   from, if you're running setuid.)  You can change both the real
   uid and the effective uid at the same time by using
   POSIX::setuid().
   $EFFECTIVE_USER_ID
   $EUID
   $  The effective uid of this process.  Example:
   $ = $;# set real to effective uid
   ($,$) = ($,$);  # swap real and effective uid
   You can change both the effective uid and the real uid at the
   same time by using POSIX::setuid().
   (Mnemonic: it's the uid you went to, if you're running setuid.)
   $ and $ can be swapped only on machines supporting
   setreuid().
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



Re: replacing multiple matches with an array

2005-01-17 Thread JupiterHost.Net
Hello,
I believe this will do what you want:
  next if grep { $rawreport_item =~ /$_/ } @possibleMatches;
Just make sure the regexes in @possibleMatches are not user supplied or 
they may try sneaky bad things :)

perl -mstrict -we 'my @m = (q(^\d+$), q(^\w+$)); for my $item (qw(123 
abc 1-2we)){ next if grep { $item =~ /$_/ } @m; print $item\n; }'

HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: replacing multiple matches with an array

2005-01-17 Thread John W. Krahn
B McKee wrote:
Hi All
Hello,
I have this bit of code in a program I'm working on.
 while (RAWREPORT) {
  next if /\f/ ;
  next if /^DATE : / ;
  next if /^\s{15,}PART / ;
  next if /^COUNTER QTY/ ;
  next if /^\s+$/  ;
  print ; # debugging purposes - other stuff here
}
It works, but I'd rather put all my patterns in an array so it's neat 
and tidy.
Something like

 my @possibleMatches = (\f,^DATE :,^\s{15,}PART ,^COUNTER 
QTY,^\s+$) ;
 while (RAWREPORT) {
  next if /@possibleMatches/
  print ; # debugging purposes - other stuff here
 }

but that doesn't work as is.  I could loop over the array I suppose and 
name each loop
something like [untested]

 my @possibleMatches = (\f,^DATE :,^\s{15,}PART ,^COUNTER 
QTY,^\s+$) ;
 OUTER:  while (RAWREPORT) {
  INNER:  foreach $my match (@possibleMatches) {
  next OUTER if /$match/
  print ; # debugging purposes - other stuff here
 }
but that doesn't seem much better to me.
Is there a common way to do this?
Comments appreciated
What you probably want is:
while ( RAWREPORT ) {
next if /\f|^DATE : |^\s{15,}PART |^COUNTER QTY|^\s+$/  ;
print ; # debugging purposes - other stuff here
}
Although you should read this first:
perldoc -q How do I efficiently match many regular expressions at once

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



Reading the first line of a file

2005-01-17 Thread David Gilden
Greetings,

The second piece of code should look for  * InTune  somewhere in the 
first line
of the file if it does not, it should unlink the bad file and fire off the 
error, it seems
to happen all the time regardless of the match.

Two quick questions here:

I can't see why I am getting this error
:  Use of uninitialized value in print

#!/usr/bin/perl -w

# code test 
use strict;

my $str =  * InTune ;

($str) = ($str =~ m/(\*{5} InTune)/);

print $str;
 
__END__

is there a way to add a -e to check to see if we have a file to unlink ?

#  Check to make sure it is an inTune File
open (FH, UPLOAD_DIR . /$file)  || error( $q, Error reading $file for test : 
 $! );

while(FH){
if ($_ !~ /\*{5} InTune/){
unlink( UPLOAD_DIR . /$file) or error( $q, Problem deleting file $!);
error( $q, The file you uploaded is not an inTune file. Only an inTune 
export file will be accepted. ); 
}
last;
} 
close FH;



Thanks,

Dave
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

Visit my schedule page for up to the minute performance info:
http://www.coraconnection.com/cgi-bin/schedule.pl


==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments  More!
   http://www.coraconnection.com/ 
==

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




Re: regular expression question

2005-01-17 Thread Stone
On Mon, 17 Jan 2005 16:04:48 -0500, Dave Gray [EMAIL PROTECTED] wrote:
  I am new to perl, I receive some spam email with subject like st0ck,
  0pportunities, gr0wth..., how can I match those words with number 0 in

What about something like this:

if ( $subject =~ /(^0[a-zA-Z]+)|([a-zA-Z]+0$)|([a-zA-Z]+0[a-zA-Z]+)/ ) {
   ...it's spam, so do something...
}

Basically it says if a word starts with 0, has 0 in the middle, or
ends in 0, it matches.

These won't match:
Perl Problem
0 compile errors, yay!
I have 20 dollars that says...
Forcast for Q1 2005
$0 sale

These will:
Great 0pportunity for you!
Buy this st0ck!
N0 money down!

Not sure exactly how you're wanting to use this, but you could use a
similar expression to replace the 0 in spam messages to o *before*
it gets to your spam filter, or just use it to as is to filter out
stuff that makes it past your spam filter.

-- 
http://xstonedogx.heroesmarket.net

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




Re: Reading the first line of a file

2005-01-17 Thread Stone
 is there a way to add a -e to check to see if we have a file to unlink ?

How about:

open (FH, UPLOAD_DIR . /$file)  || die ( $q, Error reading $file
for test :  $! );

That will stop processing at that point, if you aren't able to open
the file for any reason (like it doesn't exist).

Otherwise, how about something like:

$have_access = open (FH, UPLOAD_DIR . /$file) ? 1 : 0;
if ($have_access) {
   ...we have access to the file, so do something...
}



 if ($_ !~ /\*{5} InTune/){

This should be:

if ($_ !=~ /\*{5} InTune/) {



-- 
http://xstonedogx.heroesmarket.net

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




Re: regular expression question

2005-01-17 Thread Chris Devers
On Mon, 17 Jan 2005, Vincent wrote:

 I am new to perl, I receive some spam email with subject like st0ck, 
 0pportunities, gr0wth..., how can I match those words with number 0 
 in

You don't.

I spent a about a year doing pretty much what you're asking for here, 
though with Procmail rules instead of Perl. Same difference, in this 
case. Getting these patterns right is *really* hard to do -- as a simple 
example, what happens when someone sends you a legit mail with a zero in 
the subject line? 

  To: Vincent [EMAIL PROTECTED]
  From Vincent's significant other [EMAIL PROTECTED]
  Subject: meet for drinks at 10 First St at 8:00 tonight?

A mail like that would trip a naive filtering rule. 

  To: Vincent [EMAIL PROTECTED]
  From Vincent's significant other [EMAIL PROTECTED]
  Subject: meet for drinks at Pier01 at 8:00 tonight?

And, if such a place as Pier01 existed, you wouldn't be able to have 
it in the subject line even with a good filter running.

This is the wrong way to attack spam.

You're much better off setting up something like SpamAssassin, which 
among other things builds up a collection of little rules like this 
which then collectively determine if a message probably is or is not 
spam. Additionally, it can look at messages you explicitly classify as 
spam or non-spam, and build up a statistical profile of what does or 
does not look like spam to *you*, using Bayesian statistics. This is 
approach is far more effective than just about anything else, and is the 
general strategy that most other spam filters are using today.

If you need help setting up SpamAssassin, go to their website at 
http://spamassassin.apache.org/. They have documentation and mailing 
lists that can help you get up and running.

SA is written in Perl, so once you're running with it, you can adjust it 
as you like. If the digits in words rule is important to you and there 
isn't one for it already (there probably is, but no problem if not), you 
can add one and set a score for it as needed. You can ask for help with 
that either here or on the SA lists.



-- 
Chris Devers

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




writing newfile to a dir

2005-01-17 Thread Brian Volk
Hi All,
I created a script that renames a dir of MP3 files...  Everything is 
working well except when I try to write the new files to a directory.   
I thought I could print to a dirhandle, apparently not.. :~)  Maybe I 
need to mv the $newfile...?  not sure... Any help would be greatly 
appreciated!

Thanks! 

Brian
#!/usr/bin/perl
use strict;
use warnings;
my $mp3_dir = /home/bvolk/Dell/Shared/Mp3_to_wav;
opendir (FILES, $mp3_dir) || die Couldn't open $mp3_dir: $! \n;
my @files = grep { !/^\.\.?$/ } readdir FILES;
closedir FILES;
my $new_mp3_dir = /home/bvolk/Music/MP3_files;
opendir (NEWDIR, $new_mp3_dir) || die Couldn't open $new_mp3_dir: $! \n;
foreach my $file(@files){
   my($newfile) = lc $file;   # Lower case all file names
   $newfile =~ s/ /_/g;   # Replace spaces w/ underscores
   $newfile =~ s//and/g; # Replace ampersands
   $newfile =~ s/\'//g;   # Remove apostrophes
   $newfile =~ s/(\(|\))//g;  # Remove parenthesis
   $newfile =~ s/[\-]//g; # Remove dashes
   $newfile =~ s/,//g;# Remove commas
  
   print NEWDIR $newfile \n;
}

closedir NEWDIR;

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



Re: Counting occurences of a char in a line

2005-01-17 Thread Jenda Krynicky
From: Tor Hildrum [EMAIL PROTECTED]
 I have the following code in a script I'm writing:
 
 foreach my $line (INN) {
 if ( 10 == ($line =~ s/,/,/g) ) {
 print OUT $line;
 }
 }
 
 Is this poor style? It looks a bit ugly, but I can't figure out a
 better way to do it. I'm sure there is :) The script will be reused
 and probably maintained by someone else. Is there a more standard
 way of doing this?

You do not seem to want to count the commas, you seem to want to make 
sure there are exactly ten of them. Which means you might just as 
well use this:

foreach my $line (INN) {
if ( $line =~ /^[^,]*(?:,[^,]*){10}$/) ) {
print OUT $line;
}
}

That is check whether the full string is something not containing 
comma followed by ten times comma and something not containing 
comma.

You may later want to make the regexp a little more restrictive 
later.

Jenda

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


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




RE: Spam:Re: Reading the first line of a file

2005-01-17 Thread Michael Kraus
G'day...

  if ($_ !~ /\*{5} InTune/){
 
 This should be:
 
 if ($_ !=~ /\*{5} InTune/) {

Should it?

I always thought that !~ was the inverse of =~

I.e.
$var !~ /pattern/
was the equivalent of 
!($var =~ /pattern/)

(at least within test conditions anyway)

Is there something I'm missing?  :)

Thanks!


Regards,
 

Michael S. E. Kraus
B. Info. Tech. (CQU), Dip. Business (Computing)
Software Developer
Wild Technology Pty Ltd
___
ABN 98 091 470 692
Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia
Telephone 1300-13-9453 |  Facsimile 1300-88-9453
http://www.wildtechnology.net
 
The information contained in this email message and any attachments may
be confidential information and may also be the subject of client legal
- legal professional privilege. If you are not the intended recipient,
any use, interference with, disclosure or copying of this material is
unauthorised and prohibited.   This email and any attachments are also
subject to copyright.  No part of them may be reproduced, adapted or
transmitted without the written permission of the copyright owner.  If
you have received this email in error, please immediately advise the
sender by return email and delete the message from your system. 





Wild Technology Pty Ltd , ABN 98 091 470 692
Sales - Ground Floor, 265/8 Lachlan Street, Waterloo NSW 2017
Admin - Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017
Telephone 1300-13-9453 |  Facsimile 1300-88-9453
http://www.wildtechnology.net
DISCLAIMER  CONFIDENTIALITY NOTICE:  The information contained in this email 
message and any attachments may be confidential information and may also be the 
subject of client legal - legal professional privilege. If you are not the 
intended recipient, any use, interference with, disclosure or copying of this 
material is unauthorised and prohibited.   This email and any attachments are 
also subject to copyright.  No part of them may be reproduced, adapted or 
transmitted without the written permission of the copyright owner.  If you have 
received this email in error, please immediately advise the sender by return 
email and delete the message from your system.



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




Re: writing newfile to a dir

2005-01-17 Thread JupiterHost.Net

Brian Volk wrote:
Hi All,
Hello,
I created a script that renames a dir of MP3 files...  Everything is 
Perhaps File::Copy::Recursive can assist you in this?
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.02/Recursive.pm
use File::Copy::Recursive 'dircopy';
dircopy($orig,$new) or die Copying $orig failed: $!;
unlink $orig or die Removing $orig failed: $!;
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: writing newfile to a dir

2005-01-17 Thread Brian Volk
JupiterHost.Net wrote:

Brian Volk wrote:
Hi All,

Hello,
I created a script that renames a dir of MP3 files... Everything is 

Perhaps File::Copy::Recursive can assist you in this?
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.02/Recursive.pm
use File::Copy::Recursive 'dircopy';
dircopy($orig,$new) or die Copying $orig failed: $!;
unlink $orig or die Removing $orig failed: $!;
HTH :)
Lee.M - JupiterHost.Net
Lee,
Thanks for the help... I used rename and it worked great. I will 
definitely check out your suggestion as well.. Thanks again...
rename $mp3_dir/$file, $new_mp3_dir/$newfile;

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



Re: Reading the first line of a file

2005-01-17 Thread Stone
  if ($_ !~ /\*{5} InTune/){

 This should be:

 if ($_ !=~ /\*{5} InTune/) {

Please ignore this. Your use of the operator is correct.

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




Re: writing newfile to a dir

2005-01-17 Thread JupiterHost.Net

Brian Volk wrote:
JupiterHost.Net wrote:
Brian Volk wrote:
Hi All,

Hello,
I created a script that renames a dir of MP3 files... Everything is 

Perhaps File::Copy::Recursive can assist you in this?
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.02/Recursive.pm
use File::Copy::Recursive 'dircopy';
dircopy($orig,$new) or die Copying $orig failed: $!;
unlink $orig or die Removing $orig failed: $!;
HTH :)
Lee.M - JupiterHost.Net
Lee,
Thanks for the help... I used rename and it worked great. I will 
No problem :)
definitely check out your suggestion as well.. Thanks again...
rename $mp3_dir/$file, $new_mp3_dir/$newfile;
great, the reason it didn't work before was that to create new files you 
open() a file handle to do that, not write to a directory handle, if I 
may use that term to describe what was going on :)

perldoc -f open
perldoc -f opendir
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



calling Tcl script with ato arguments

2005-01-17 Thread Vladimir Lemberg
Hi All,

Could you help me to solve following problem:

I need to execute tkl script with two arguments (input file and output file) 
within my Perl script:

#!/usr/bin/perl -w
use strict;
use File::Basename;

my @gdflist = `find . -name *.gdf`;
my $gdf_number = scalar(@gdflist);
my $counter = 0;

 foreach my $gdf (@gdflist){
   my $base = basename $gdf;
   my $path = dirname $gdf;
   $base =~ s/(.*)(\.)/$1$2/;
 
chomp($gdf);
my $arg1 = $gdf;
my $arg2 = $path/$1_patched.gdf;
 
 system patch_teleatlas_gdf.tcl $arg1 $arg2 or die 
patch_teleatlas_gdf.tcl is not working properly;
 $counter ++;
 print \{$gdf\}:PATCHED($counter of $gdf_number);
}

The problem that I'm receiving the die message patch_teleatlas_gdf.tcl is not 
working properly but then I manually assign arguments, 
Tcl script works with no problem.

my arg1 = ./CSK/cansk47.gdf;
my arg2 = ./CSK/cansk47_patched.gdf;
system patch_teleatlas_gdf.tcl $arg1 $arg2 or die patch_teleatlas_gdf.tcl is 
not working properly;

Any ideas? Should i use execvp(3) instead?

Thanks in advance,
Valdimir 









Re: calling Tcl script with ato arguments

2005-01-17 Thread Randy W. Sims
Vladimir Lemberg wrote:
Hi All,
Could you help me to solve following problem:
I need to execute tkl script with two arguments (input file and output file) 
within my Perl script:
#!/usr/bin/perl -w
use strict;
use File::Basename;
my @gdflist = `find . -name *.gdf`;
my $gdf_number = scalar(@gdflist);
my $counter = 0;
 foreach my $gdf (@gdflist){
   my $base = basename $gdf;
   my $path = dirname $gdf;
   $base =~ s/(.*)(\.)/$1$2/;
 
chomp($gdf);
my $arg1 = $gdf;
my $arg2 = $path/$1_patched.gdf;
 
 system patch_teleatlas_gdf.tcl $arg1 $arg2 or die patch_teleatlas_gdf.tcl is not working properly;
 $counter ++;
 print \{$gdf\}:PATCHED($counter of $gdf_number);
}

The problem that I'm receiving the die message patch_teleatlas_gdf.tcl is not working properly but then I manually assign arguments, 
Tcl script works with no problem.

my arg1 = ./CSK/cansk47.gdf;
my arg2 = ./CSK/cansk47_patched.gdf;
system patch_teleatlas_gdf.tcl $arg1 $arg2 or die patch_teleatlas_gdf.tcl is not 
working properly;
Any ideas? Should i use execvp(3) instead?
Csystem returns the exit code of the program executed. Most programs 
return 0 (zero) on success. However, zero is treated as a false value in 
perl, so your Cor condition above is executed when the tcl script 
succeeds. You need to compare the result of system to zero to determine 
success:

system(...) == 0 or die;
A more perlish version of your script might look like (untested):
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Spec;
my $script = 'tickle.tcl';
my $count = 0;
find( sub {
return unless /\.gdf/  -f;
(my $base = $_) =~ s/\.[^.]+$//;
my $src  = $File::Find::name;
my $dest = File::Spec-catfile( $File::Find::dir, 
${base}_patched.gdf );

system( $script, $src, $dest ) == 0
or die error code $? returned: $!;
++$count;
}, 'downloads' );
print $count files patched\n;
__END__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Substitute Varaible

2005-01-17 Thread Anish Kumar K.
Thanks it is working fine

Anish

- Original Message - 
From: Dave Gray [EMAIL PROTECTED]
To: beginners perl beginners@perl.org
Sent: Monday, January 17, 2005 11:43 PM
Subject: Re: Substitute Varaible


 On Mon, 17 Jan 2005 16:11:54 +0530, Anish Kumar K.
 [EMAIL PROTECTED] wrote:
  Hi I need help regarding substituion of varaibles with values
  
  Say I have a txt file (a.txt)
  
  which has only one line:
  Hi $name
  
  The PL file
  
 
   use strict;
   use warnings;
 
  open INPUT, a.txt;
 
 Always check the success of file opens!
   open INPUT, ' a.txt' or die couldn't read a.txt: $!\n;
 
  my $name=Anish;
  my $temp=;
  while (INPUT)
  {
$temp=$temp.$_;
 
 This could also be written as:
   $temp .= $_;
 Personal preference, I guess.
 
  }
  close(INPUT);
  print Content is: $temp;
  
  In the output I want the $name to get as Anish..O/P like Hi Anish
 
 Check out the eval built-in:
   close(INPUT);
   # evaluate the content of $temp as perl[1]
   # this won't work if there are any double quotes in $temp
   $temp = eval qq/$temp/;
 
 There is probably a better way to do what you're trying to
 accomplish... can you give us a bigger picture?
 
 HTH,
 Dave
 
 [1] http://www.perldoc.com/perl5.8.4/pod/func/eval.html
 
 -- 
 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: Counting occurences of a char in a line

2005-01-17 Thread Tor Hildrum
On Tue, 18 Jan 2005 01:08:56 +0100, Jenda Krynicky [EMAIL PROTECTED] wrote:

 foreach my $line (INN) {
 if ( $line =~ /^[^,]*(?:,[^,]*){10}$/) ) {
 print OUT $line;
 }
 }
 
 That is check whether the full string is something not containing
 comma followed by ten times comma and something not containing
 comma.

This is a script for an awful system where I only have access to a
certain part of the whole system. It's a web-form with 10 fields.
Instead of putting
the fields directly into a database, I get the fields as a comma-seperated list
on email. One mail for each request(!). 
So, I'm basically parsing a huge mbox-file here.

I have no power over the webmaster, and he won't listen to reason. 
The fields may or may not be empty. So, valid format is:
[EMAIL PROTECTED],bar,foo,bar,foo,bar,foo,bar,foo, bar, foo
and
[EMAIL PROTECTED],,
and
foo,bar,,,

I'm basically just checking for 10 commas, write it to it's own file
and then use a mysql-import script on that file. Any lines with more
than 11 commas get's flagged for manual checking.

To make matters even worse, we are using Matt's Formmail script. I'm
not sure if it's gotten better, but last time I checked it didn't have
the best of track records.

I ended up using tr//, even though it sports almost the same
readability as s// it seems more correct.

Thanks.

Tor

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




Is CYGWIN a unix like environment to run PERL modules?

2005-01-17 Thread Zapa Perl
Hello,
 
I installed CYGWIN on Win-2000 hoping to have a Linux like environment and run 
PERL.
I was expecting to click on the CYGWIN desktop icon and get a prompt window and 
move on.
but that is not what I got. when I double click on CYGWIN desktop icon 
something flashes
and disappears quickly and no chance of doing anything.
how do I get to CYGWIN prompt window? 
or how do I get to Linux like environment to run my PERL modules?
thank you in advance.
Zapa.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com