Re: cookies and web

2001-05-01 Thread C.J. Collier

Heya Jeff,

   You might consider HTTP::Cookies.  You can use it with LWP by telling 
the useragent to use a new cookie object to grab cookies from the HTML 
headers.  You'll get a lot more from perldoc HTTP::Cookies, but 
following is an example,

Cheers,
   C.J.

#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Cookies;

my $ua = new LWP::UserAgent;
$ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave => 1));

my $url = "http://foo.com/bar.html";;
$url = $ARGV[0] if(@ARGV);

my $res = $ua->simple_request(GET $url);

while ($res->is_redirect) {
  my $url = $res->header('location') or
  die "missing location: ", $res->as_string;
  print "redirecting to $url\n";
  $res = $ua->simple_request(GET $url);
}
print $res->as_string, "\n", $ua->cookie_jar->as_string(), "\n";


> Hi,
> 
> How do i go about accepting a cookie from a web login site?
> 
> I use LWP to do a POST, but i can't login as the server
> sends a cookie. Is there a generic Login perl script lines?
> 
> Login to a web site, send username password, accept cookie
> then the rest of the POST forms send that cookie back?
> 
> Thanks
> Jeff.






RE: cookies and web

2001-05-01 Thread King, Jason

Jeff K.V. Bhavnanie writes ..

>How do i go about accepting a cookie from a web login site?

in a cookie jar

>I use LWP to do a POST, but i can't login as the server
>sends a cookie. Is there a generic Login perl script lines?
>
>Login to a web site, send username password, accept cookie
>then the rest of the POST forms send that cookie back?

nope .. no generic one .. but it's pretty simple .. if you're not already -
then you'll need to start using LWP::UserAgent (rather than LWP::Simple)

then check out the documentation

  perldoc LWP::UserAgent

search for cookie and you'll see the cookie_jar method .. and a reference to
HTTP::Cookies .. check the documentation for that too

  perldoc HTTP::Cookies

it's pretty simple

Hint: test cookie scripts first on the command line - it's MUCH easier to
see and debug the output

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: CGI Problem

2001-05-01 Thread J. Patrick Lanigan

Yeah, the CLI gave me the expected result. I am pretty stumped at this
point. I have added everything to my httpd.conf that should be in there. And
I am geting a different error than before, so I am confident that the file
is found.

Anyone have any other ideas?

Thanks Jason,
Patrick

> jason king wrote:
>
> J. Patrick Lanigan writes ..
>
> >I tried them on th CLI first. I even su'ed to user nobody to
> >match the env of apache.
>
> and on the CLI - I presume that they outputted exactly what you
> expected ..
> ie.
>
> "Content-type: text/html
>
> Hello World!
> "
>
>
> it doesn't seem like a permissions error .. I presume that this is in a
> cgi-script directory .. or you have the appropriate extension mapping in
> your conf file ?
>
> other than that - I really can't think of anything else




RE: how to ??

2001-05-01 Thread King, Jason

Daniel Choong writes ..

>okie, this probably sounds very simple but i dunno how
>to do it. i just learnt perl. i need some tips on how
>to use a perl script to automate the updating of files
>on multiple servers. i am trying to use ftp but i do
>not know how to write the script to read the output
>from ftp, then send the username and passwd, then
>detect the prompt and send the commands. i suppose
>there's a simple way to do that but i am lost.
>anyone knows how to do that? i tried using IPC::Open2
>but i dunno how to use it properly.


for FTP take a look at the Net::FTP module .. it should be part of the
standard distribution .. you can view the help with the perldoc utility
which is installed with Perl .. type the following at a command prompt

  perldoc Net::FTP

if it's not installed then you'll find as part of the libnet bundle - here

  http://search.cpan.org/search?dist=libet

the examples in the documentation make any examples here redundant

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: CGI Problem

2001-05-01 Thread King, Jason

J. Patrick Lanigan writes ..

>I tried them on th CLI first. I even su'ed to user nobody to 
>match the env of apache.

and on the CLI - I presume that they outputted exactly what you expected ..
ie.

"Content-type: text/html

Hello World!
"


it doesn't seem like a permissions error .. I presume that this is in a
cgi-script directory .. or you have the appropriate extension mapping in
your conf file ?

other than that - I really can't think of anything else

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



cookies and web

2001-05-01 Thread Jeff K.V. Bhavnanie

Hi,

How do i go about accepting a cookie from a web login site?

I use LWP to do a POST, but i can't login as the server
sends a cookie. Is there a generic Login perl script lines?

Login to a web site, send username password, accept cookie
then the rest of the POST forms send that cookie back?

Thanks
Jeff.



RE: CGI Problem

2001-05-01 Thread J. Patrick Lanigan

I tried them on th CLI first. I even su'ed to user nobody to match the env
of apache.

> King, Jason wrote:
>
> J. Patrick Lanigan writes ..
>
>
> >I am getting an "Internal Server Error" returned to my
> >browser. The error
> >log shows the following:
> >
> >"[Wed May  2 00:04:39 2001] [error] [client 192.168.0.10]
> >Premature end of
> >script headers: /path/to/filename"
>
>
> your scripts are very simple which would suggest that it's
> something that's
> happening prior to the scripts being interpreted .. what happens when you
> run the files from the command line like this ?
>
>   /path/to/filename
>
> perhaps your shebang line is not right ??
>
> --
>   jason king
>
>   In New York, a fine of $25 can be levied for flirting. This old law
>   specifically prohibits men from turning around on any city street and
>   looking "at a woman in that way." A second conviction for a crime of
>   this magnitude calls for the violating male to be forced to wear a
>   "pair of horse-blinders" wherever and whenever he goes outside for a
>   stroll. - http://dumblaws.com/




RE: CGI Problem

2001-05-01 Thread King, Jason

J. Patrick Lanigan writes ..


>I am getting an "Internal Server Error" returned to my 
>browser. The error
>log shows the following:
>
>"[Wed May  2 00:04:39 2001] [error] [client 192.168.0.10] 
>Premature end of
>script headers: /path/to/filename"


your scripts are very simple which would suggest that it's something that's
happening prior to the scripts being interpreted .. what happens when you
run the files from the command line like this ?

  /path/to/filename

perhaps your shebang line is not right ??

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



how to ??

2001-05-01 Thread Daniel Choong



okie, this probably sounds very simple but i dunno how
to do it. i just learnt perl. i need some tips on how
to use a perl script to automate the updating of files
on multiple servers. i am trying to use ftp but i do
not know how to write the script to read the output
from ftp, then send the username and passwd, then
detect the prompt and send the commands. i suppose
there's a simple way to do that but i am lost.
anyone knows how to do that? i tried using IPC::Open2
but i dunno how to use it properly.
daniel



__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



CGI Problem

2001-05-01 Thread J. Patrick Lanigan

I am getting an "Internal Server Error" returned to my browser. The error
log shows the following:

"[Wed May  2 00:04:39 2001] [error] [client 192.168.0.10] Premature end of
script headers: /path/to/filename"

I have set the directory and file to 755 and the correct ownership. I have
tried a couple simple scripts and gotten the same error:

_First_Script_

#!/usr/bin/perl
print "Content-type: text/html\n\n";
foreach $key (keys %ENV) {
 print "$key --> $ENV{$key}";
}

_Second_Script_

#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "Hello World!\n";

Any ideas would be appreciated,
Patrick






RE: RegEx Prob WAS: Problem with reading string

2001-05-01 Thread J. Patrick Lanigan

I just keep learning. This list is making learning much easier.

Thanks to Dan and Jason,
Patrick

> you need the global modifier .. what you're trying to do is do the current
> match globally throughout the whole string (not zero or more)
>
>   $mystring =~ s/\'/\\'/g;




RE: test if a directory exists if it does delete it else print di rectory does not exists

2001-05-01 Thread King, Jason

I wrote ..

>so .. your code could probably have looked something like this 
>(using the wonderful File::Path module)
>
>  #!perl -w
>  use strict;
>
>  use File::Path 'rmtree';
>
>  open DIRS, 'c:/admin/removedir.txt' or die "Bad open: $!";
>  chomp( my @dirs = );
>
>  rmtree( \@dirs);
>
>  __END__
>
>have fun


and I only just noticed the subject of the email .. which my code doesn't do
.. so here's a replacement

  #!perl -w
  use strict;

  use File::Path 'rmtree';

  open DIRS, 'c:/admin/removedir.txt' or die "Bad open: $!";

  chdir 'c:/admin/test';

  while()
  {
chomp;

if( not -d ) { print qq/Directory "$_" does not exist.\n/; next }

rmtree $_ or print qq/\n\tDirectory deletion of "$_" failed.\n\n/;
   
  }

  __END__

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: test if a directory exists if it does delete it else print directory does not exists

2001-05-01 Thread King, Jason

Peter Lemus writes ..


>I need to delete some directories, specified in
>removedir.txt, I'll like to check whether the file
>exists or not, if it doesn't I need to print file has
>been deleted.  this is what I've done so far.

ok .. line by line (and excuse the pedantry)

>use file::spec;
>use win32;

please use the correct case for modules .. just because Windows ignores case
- doesn't mean Perl programmers should .. that having been said you don't
use either of the above modules

>chdir ("c://admin");

why change directory here ? .. and why the double forward slash ?

>open (FILE1, 'c://admin//remove.txt') ||  die "can't...: $!\n";

from your spec - the above file is incorrect (and again with the double
forward slashes) .. it should be

  open (FILE1, 'c:/admin/removedir.txt') || die "...: $!\n";

>sleep 2;

what ? .. you want your program to run slower ? .. there's no reason to
sleep here

>while () { # read file line by line.
>my ($user) = split /,/; #assign line output of file to line.

actually - the comment is wrong here .. what this line is doing is assigning
whatever comes before a comma on this line to the variable $user .. if
there's no comma then the whole line is assigned

> chdir ('c://admin//test');

again with the double forward slashes ?

> chomp $user;

yep .. for lines without commas this strips off the EOL character

>rmdir "/s /\q $user"; 

rmdir is a Perl function .. it doesn't take the same parameters as the DOS
command

  perldoc -f rmdir

and it only works if the directory is empty

># system ('rmdir /s /q $user');

the above attempt would have worked if you'd have used double quotes instead
of single quotes .. double quotes allow variables to be interpolated
(obviously you'd also need to uncomment this line)

>#system ('rmdir /s /q $user'); # remove directory

so you tried it with and without a trailing comment :) .. this line would
also have worked with double quotes

># if (-d ) { # check if file exist: "please help me here"
>   }

the 'rmdir' should be inside that if statement .. although it's harmless if
there's no matching directory .. the DOS rmdir will print to STDERR an error
message which may be undesirable

>print "Specified directory has been deleted \n";
>sleep 2;

again .. slowing the program down - why ?

>}

the end of the while is here I guess .. so if there is more that one
directory on the one line separated by commas (as your split seems to
suggest) then only the first one will be processed

>close FILE1

although the last statement doesn't have to have a trailing semi-colon ..
it's still good practice to use one .. although I don't usually close
filehandles that have been opened for reading .. Perl closes them for you
when it exits

so .. your code could probably have looked something like this (using the
wonderful File::Path module)

  #!perl -w
  use strict;

  use File::Path 'rmtree';

  open DIRS, 'c:/admin/removedir.txt' or die "Bad open: $!";
  chomp( my @dirs = );

  rmtree( \@dirs);

  __END__

have fun

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



Re: Problem with reading string

2001-05-01 Thread Dan Brown

Use the 'g' switch so the pattern match is

$mystring =~ s/\'/\\'/g;

This 'g' says do it for all occurrences (I remember it by thinking of it
as the 'g' in 'globally').

Dan

"J. Patrick Lanigan" wrote:
> 
> I was using:
> 
> $mystring =~ s/\'/\\'/;
> 
> ...to replace ' with \' in $mystring. It was working find I thought, until I
> encountered a string with multiple apostrophies. How do I replace 0 or more?
> 
> Ex:
> 
> "No More 'I Love You's'"
> 
> ...should become:
> 
> "No More \'I Love You\'s\'"
> 
> I've tried:
> 
> $mystring =~ s/\'*/\\'/;
> $mystring =~ s/(\')*/\\'/;
> 
> ...neither of which work.
> 
> Any help would be greatly appreciated. And no cracks about the Annie Lennox
> song title, it is my wifes' part of our mp3 collection :-)
> 
> Thanks,
> Patrick



test if a directory exists if it does delete it else print directory does not exists

2001-05-01 Thread Peter Lemus

HI Folks,

I need to delete some directories, specified in
removedir.txt, I'll like to check whether the file
exists or not, if it doesn't I need to print file has
been deleted.  this is what I've done so far.

use file::spec;
use win32;
chdir ("c://admin");
open (FILE1, 'c://admin//remove.txt') ||  die "can't
open file he: $!\n";
sleep 2;
while () { # read file line by line.
my ($user) = split /,/; #assign line output of file to
line.
 chdir ('c://admin//test');
 chomp $user;
rmdir "/s /\q $user"; 
# system ('rmdir /s /q $user');
#system ('rmdir /s /q $user'); # remove directory
# if (-d ) { # check if file exist: "please help
me here"
}
print "Specified directory has been deleted \n";
sleep 2;
 } 
close FILE1
EOF


=
Peter Lemus
Computer Networks Engineer
[EMAIL PROTECTED]
My Dad always tought me; when you do good; expect to receive good; when you do bad; 
expect the bad...sooner or later.

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



RE: RegEx Prob WAS: Problem with reading string

2001-05-01 Thread King, Jason

J. Patrick Lanigan writes ..


>> I was using:
>>
>>  $mystring =~ s/\'/\\'/;
>>
>> ...to replace ' with \' in $mystring. It was working find I
>> thought, until I
>> encountered a string with multiple apostrophies. How do I replace
>> 0 or more?
>>
>> Ex:
>>
>>  "No More 'I Love You's'"
>>
>> ...should become:
>>
>>  "No More \'I Love You\'s\'"
>>
>> I've tried:
>>
>>  $mystring =~ s/\'*/\\'/;
>>  $mystring =~ s/(\')*/\\'/;
>>
>> ...neither of which work.


you need the global modifier .. what you're trying to do is do the current
match globally throughout the whole string (not zero or more)

  $mystring =~ s/\'/\\'/g;

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: running gzip with the system function

2001-05-01 Thread King, Jason

lance turner writes ..


>Thanks Jason for your reply.
>
>I tried using an absolute path for gzip, but I'm getting the 
>same error.
>
>I don't understand why I can run gzip from the shell but can't run it 
>through perl. I'm able to run tar and other programs using the system 
>function but not gzip.

it might be a permission issue on the gzip program .. are you running this
program yourself from the command-line ? .. or is it being run via CGI or
something ?

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: Perl and NT

2001-05-01 Thread King, Jason

Matt Blatchley writes ..


>Does anyone know of a way to use perl and CGI to have the following:
>
>html page w/ form to get stdin from the user for username and
>password.(basic),

>pass the variables to the perl script which then modifies permissions
>for a specific folder on NT and allows the user to then have access to
>a particular folder after having the password emailed to the user...

yes you can do it .. but the CGI program (be it Perl or ASP/vbscript) will
only have the security privileges of whatever account the web server is
configured to access the CGI directory as

this is usually a builtin account called something like

  IUSR_machinename

and it's usually only a Guest .. because Guests can't change permissions on
directories then you'll run into problems

once you've changed that account then you have to be REALLY careful with the
programs that you write and the web server in general (especially with
WebDAV now in IIS5) because users will have higher privileges on your system

to actually change the permissions you can use a Perl module called

  Win32::FileSecurity

which ships with the standard distribution of Win32 Perl .. or you can just
call cacls.exe with the system command  .. it's a WinNT utility for change
the ACL (permissions)

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: finding common records between two files

2001-05-01 Thread King, Jason

Mike Stussie writes ..

>I'm a newbie to perl and trying to solve a problem.. Here is what I'm 
>trying to do:
>
>read thru flat file 'A' that looks something like this:(fields 
>delimited by
>'::')
>BCSNDTJN::Joe User::1 N.
>Main::Anytown::MO::None::None::None::Unknown::[EMAIL PROTECTED]
>
>and find any duplicates based on the email address that might be in
>flat file 'B'. I want to take the duplicates and output it to another
>file so that I can administer it later.
>
>I found something in the camel book relating to hashes that might do
>the trick but how do I get the flat file into a hash.


excuse me if I've misunderstood - but you seem to be having fun working
through things yourself and seem to be just looking for a solution to the
"how do I read a file into a hash" question .. rather than a solution to the
whole thing

so I'll just provide that - in case solving it all will be wrecking your fun
(let me know if I've guessed wrong .. because it's a very simple program to
show you)

also .. your description is unclear .. but I'm assuming that flat file 'B'
contains just email addresses .. eg.

  [EMAIL PROTECTED]
  [EMAIL PROTECTED]
  [EMAIL PROTECTED]

so .. here's the trick .. you use the map function to create a new list
where the lines from 'B' are the keys and you just give them a true value
(we're using 1 here)

  open IN, 'B' or die "Bad open: $!";
  my %check = map { chomp; $_ => 1 } ;

so .. if the above example email addresses were in 'B' then now you'd have
the following hash

  $check = ( '[EMAIL PROTECTED]' => 1,
 '[EMAIL PROTECTED]' => 1,
 '[EMAIL PROTECTED]'  => 1
   );

so hopefully your camel example will now enable you to look through 'A'
checking whether the email address is a duplicate

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: Question on optimizing this sub (help!)

2001-05-01 Thread King, Jason

Shawn writes ..


>Can someone look at a subroutine for me? Specifically, after
>this (at bottom of email) subroutine runs, it increases my
>RSS by 6 megs, and shouldn't do that. (here it has indexed
>133798 files)

this is normal Perl behaviour - welcome to an interpreted language .. check
out the Perl FAQ .. it will have been installed on your system with perl ..
type the following at the command prompt

  perldoc -q "free.*array"

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RE: Using Email

2001-05-01 Thread King, Jason

Phillip Bruce writes ..

>  Anyone with experience in having perl call up mailx and
>  at the same time have the body of the messages sent along
>  with attachment.


using mailx is almost certainly not the ideal solution for your system ..
there are a number of Perl modules that deal with sending mail .. they all
have different merits

my personal favourite (but by no means your only or even best choice) is

  Mail::Sender

it handles sending attachments nicely .. and it's platform independant (ie.
it makes the SMTP socket connection directly rather than relying on sendmail
- NB: most of the available modules are at least capable of doing this now
too)

get it from CPAN

  http://search.cpan.org/search?dist=Mail-Sender

it's probably available via PPM if that's your cup of tea

-- 
  jason king

  In New York, a fine of $25 can be levied for flirting. This old law
  specifically prohibits men from turning around on any city street and
  looking "at a woman in that way." A second conviction for a crime of
  this magnitude calls for the violating male to be forced to wear a
  "pair of horse-blinders" wherever and whenever he goes outside for a
  stroll. - http://dumblaws.com/



RegEx Prob WAS: Problem with reading string

2001-05-01 Thread J. Patrick Lanigan

Opps, I forgot to change the subject. I think I need to get outside and get
some fresh air.
> I was using:
>
>   $mystring =~ s/\'/\\'/;
>
> ...to replace ' with \' in $mystring. It was working find I
> thought, until I
> encountered a string with multiple apostrophies. How do I replace
> 0 or more?
>
> Ex:
>
>   "No More 'I Love You's'"
>
> ...should become:
>
>   "No More \'I Love You\'s\'"
>
> I've tried:
>
>   $mystring =~ s/\'*/\\'/;
>   $mystring =~ s/(\')*/\\'/;
>
> ...neither of which work.
>
> Any help would be greatly appreciated. And no cracks about the
> Annie Lennox
> song title, it is my wifes' part of our mp3 collection :-)
>
> Thanks,
> Patrick




RE: Problem with reading string

2001-05-01 Thread J. Patrick Lanigan

I was using:

$mystring =~ s/\'/\\'/;

...to replace ' with \' in $mystring. It was working find I thought, until I
encountered a string with multiple apostrophies. How do I replace 0 or more?

Ex:

"No More 'I Love You's'"

...should become:

"No More \'I Love You\'s\'"

I've tried:

$mystring =~ s/\'*/\\'/;
$mystring =~ s/(\')*/\\'/;

...neither of which work.

Any help would be greatly appreciated. And no cracks about the Annie Lennox
song title, it is my wifes' part of our mp3 collection :-)

Thanks,
Patrick




Re: writing an array to file

2001-05-01 Thread Sean O'Leary

At 12:28 PM 5/1/2001, you wrote:
>sub wanted {
> @FILES = ();
> if ( $File::Find::name =~ /_boot\.js$/ )
> {
>push @FILES, "$File::Find::name\n";
> }
>
> print (@FILES);
>
> open(BOOT_FILES,">boot_files.txt");
> print BOOT_FILES @FILES;
> close BOOT_FILES;
>}
>
>Kaustav

Well, you have to call the 'wanted' sub as part of a call to find.  You'll 
want to say something like this at the top of your program:

use File::Find;

find \&wanted, "/dir/to/look/for/files/in";

sub wanted {
 # put the body of your sub here.
}

Now, your sub will be run each time that the subroutine find 'finds' a 
file.  So if you want to print all of the files, you should push all of the 
names into an array that doesn't get initialized at the top of the sub.  In 
that case, the array is emptied each time, and then one filename pushed in, 
then the contents of the array (one element) printed to STDOUT, then the 
file opened (truncating it to 0 bytes,) the contents of the array written 
to it, and the file closed.  The whole process is repeated each time you 
come to a new file.

What you want to do is this.  Move all of the file stuff out of the wanted 
sub, as well as the initialization of the array, leaving only the if 
statement really.  You want to initialize the array once, before you start 
finding files, push all of the names you want into that array as you are 
finding them, and then print all the stuff out the file when you are 
done.  Something like this:

use strict;
use File::Find;

my @files = ();

find \&wanted, "/path/to/search";

# The "... or die ..." below is always a good idea.
# You never know when you won't be able to open a file up.
open FILE, "> outfile" or die "Can't open outfile: $!\n";
print FILE @files;
close FILE;

# Put your wanted sub down here, minus the code you need to take out.


And that's it.  I hope this helps.  I think the only thing that you needed 
to realize is that this sub isn't run once after you have found all the 
files, but each time you come across one.  As such, it can be called MANY 
times, so you want to keep it as short and sweet as possible, not to 
mention use any available speed hacks. (But don't worry about those now.)

Thank you for your time,

Sean.




Re: writing an array to file

2001-05-01 Thread Paul


--- Kaustav Bhattacharya <[EMAIL PROTECTED]> wrote:
> I have an array populated with data, I want to dump its content to
> file but
> my following code is not writing any data out! HELP:
> 
> sub wanted {
>   @FILES = ();
>   if ( $File::Find::name =~ /_boot\.js$/ )
>   {
>  push @FILES, "$File::Find::name\n";
>   }
> 
>   print (@FILES);
> 
>   open(BOOT_FILES,">boot_files.txt");

looks okay at first cursory glance
try adding to the line above:   or die $!;

and maybe opening it append, >> instead of >.
Could you be calling the function later with no value and blasting
previous output?

>   print BOOT_FILES @FILES;
>   close BOOT_FILES;
> }
> 
> 
> Kaustav
> 


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: IF statements

2001-05-01 Thread Casey West

On Tue, May 01, 2001 at 01:22:59PM -0700, Paul wrote:
: 
: --- Kaustav Bhattacharya <[EMAIL PROTECTED]> wrote:
: > Mark,
: > I only recently started coding in PERL so don't take the following as
: > official.
: > 
: > There is no CASE statement in PERL. Instead you use something called
: > SWITCH. 
: > The O'Reilly book has an example of how to use the SWITCH statement.
: 
: Perl has no CASE *or* SWITCH statement.
: You can build one, but it doesn't *have* one.
: 
: c.f. perldoc perlsyn
: 
: There's a section on switch statements. =o)

Not to mention the ever usefull module called Switch :)

Check it out at:

http://search.cpan.org/doc/DCONWAY/Switch-2.02/Switch.pm

-- 
Casey West



[OT]RE: IF statements (the ugliest SWITCH! =o)

2001-05-01 Thread Paul


--- Kaustav Bhattacharya <[EMAIL PROTECTED]> wrote:
> Mark,
> I only recently started coding in PERL so don't take the following as
> official.
> 
> There is no CASE statement in PERL. Instead you use something called
> SWITCH.

Another trick, possibly not for beginners but sometimes handy:

my %switch = ( 
   abc => sub { do_abc_code(); },
   def => \&def_sub,
   ghi => sub { $ghi++ },
);

foreach my $val (@LIST_OF_STUFF) {
   &$switch{$val};
}

This is presented merely as an excercise for the adventurous;
DON'T expect it to be a fast way to write production code until you
really understand it!

Feel free to write me and ask if you're actually interested, tho,
lol

Paul

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



RE: IF statements

2001-05-01 Thread Paul


--- Kaustav Bhattacharya <[EMAIL PROTECTED]> wrote:
> Mark,
> I only recently started coding in PERL so don't take the following as
> official.
> 
> There is no CASE statement in PERL. Instead you use something called
> SWITCH. 
> The O'Reilly book has an example of how to use the SWITCH statement.

Perl has no CASE *or* SWITCH statement.
You can build one, but it doesn't *have* one.

c.f. perldoc perlsyn

There's a section on switch statements. =o)

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: Strange chop behaviour

2001-05-01 Thread Paul


--- Francis Henry <[EMAIL PROTECTED]> wrote:
> Craig,
> 
> I'm a newbie too, but isn't the function "chomp"?

chomp is the one Craig seems to need, but there's also a chop.
chop() alsways knock a character off; chomp only pops input record
seperators (like newline, or CRLF, depending on what the value of $/
is).

perldoc -f chop
perldoc -f chomp

> Francis
> 
> Craig Moynes/Markham/IBM wrote:
> 
> > A little background.  I am running an scp process within a perl
> script and
> > redirecting the error to a file (scp_err).   I then read in the
> lines of
> > this file and attempt to place them in an error string to log to
> syslog.
> >
> > Code Sample:
> >
> > #!/usr/bin/perl -w
> > open ( ERR, " > my ( $err_msg ) = "";
> > while ( !eof(ERR) )
> > {
> > my ( $in ) = "";
> > $in = ;
> > chop $in;
> > print "$in\n";
> > $err_msg = $err_msg . $in;
> > }
> > print "Message - $err_msg\n";
> >
> > Now I have added a lot of extra print statements for debugging
> purposes.
> >
> > Sample Output:
> > ssh: HOST: Host not found
> > lost connection
> > lost connectionHOST: Host not found
> >
> > The first two lines being each line in the scp_err file, and the
> last line
> > being the final line.
> >
> > If I remove the chop then it works fine (except for the newline
> char that I
> > want to remove).  If I replace the chop with a  s/\n$// then it
> gives the
> > same output.
> >
> > Any ideas why this is occurring ?
> > -
> > Craig Moynes
> > Internship Student
> > netCC Development
> > IBM Global Services, Canada
> > Tel: (905) 316-3486
> > [EMAIL PROTECTED]
> 


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: Hash of Arrays Question

2001-05-01 Thread Paul


--- "J. Patrick Lanigan" <[EMAIL PROTECTED]> wrote:
> I haven't quite sorted out the more complex data structure in perl
> yet. Anyhow, I need to take the following hash of arrays...
> 
> my %tracks = ();
> 
> push @{$tracks{$filename}},
>   $_, # tracks.filename  
> $File::Find::dir . '/', #
> tracks.filepath
>   $artist,# artist.artist_name
>   $album, # album.title
>   $tracknum,  # tracks.track_num
>   $title, # tracks.title
>   $genre; # tracks.title

try 
   $tracks{$filename} = [ $_, $artist, $foo, $blah ];

then to get back $foo, use
   $tracks{$filename}[2];

square brackets return a reference to an anonymous array.
curly braces do the same with hashes, so you could even say

   $tracks{$filename} = { artist => $artist,
  genre  => $genre,  # etc, etc
};

and then retrieve the pieces named like this:

  print $tracks{$filename}{artist};

That should be a little easier to read.
check perldoc perlref.
   
> ...and then extract the data...(This isn't working)
> 
> for my $row ( keys %tracks ){
>   (my $qualified_filename, my $filename, my $filepath, $artist,

is that an oops? =o)

> $album,..., $title, $genre) = "$row @{ $tracks{$row} }";

Ah. It's the quotes.^   ^
That makes it a single scalar value, which gets dumped into your first
field.

> { 
  ^ oops again? lol

> ...what I end up with, is ALL my data in $qualified_filename.

quotes.

Good luck!

Paul

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



RE: open file, find lines and print to a second file....

2001-05-01 Thread Paul

--- "McCormick, Rob E" <[EMAIL PROTECTED]> wrote:
> 
> print RESULT grep { ! /_vti_cnf/ } ;
> 
> # so that could be read as print to the output filehandle the result
> of the input file handle filtered by grep.

Exactly, and because grep is a list context, the one statement prints
the entire set of matching records from the input file.

The only real caveat is that you might not want to do this sort of
thing with a very large file, because if I'm not mistaken, grep() will
build the entire array in memory before passing it to print.

> wow -  pretty concise line thereworks well.

Thanks. I was proud of it, lol...
 
> I'll need to look up $0 (perldoc perlvar:  Contains the name of the
> file containing the Perl script being executed. )

Exactly. Die puts file and line if you don't end your args with a
newline, though. =o)

Paul

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: Is there an ODBC module in perl ?

2001-05-01 Thread Casey West

On Mon, Apr 09, 2001 at 07:21:24PM -, Perl Programmer wrote:
: Is there an ODBC module in perl ?

Yes, search for 'ODBC' at http://search.cpan.org/

If you are using windows as your client operating system, and have
ActiveStat Perl installed, an ODBC driver has already been installed
by default.

Enjoy!

-- 
Casey West



RE: running gzip with the system functiou.qtontent-Type: text/plain; charset="us-ascii" ; format="flowed"

2001-05-01 Thread lance turner

Thanks Jason for your reply.

I tried using an absolute path for gzip, but I'm getting the same error.

I don't understand why I can run gzip from the shell but can't run it 
through perl. I'm able to run tar and other programs using the system 
function but not gzip.

I'm thinking that I should try a different approach - maybe using a 
pipe or something. It seems like there should be a way to run gzip.

I also looked into the Archive Zip module, but the site is running on 
a shared server and installing the module, the modules it depends on, 
and the zlib library isn't really an option.

lance

At 11:03 AM +1000 5/1/01, King, Jason wrote:
>lance turner writes ..
>
>
>>I'm trying to use the system function to run the gzip program with
>>the following line of code:
>>
>>  $status = system("gzip $filename");
>>
>>  where $filename is the file that is to be compressed
>>
>>It isn't working and a status of 65280 is being returned.
>
>return codes from system are left shifted by 8 (so that other codes can be
>included in the mask) .. so to get the real return code you have to shift
>right
>
>   perldoc -f system
>
>65280 >> 8 is 255 .. depending on your system - this return code could mean
>anything
>
>my guess is that it means that the system couldn't find the 'gzip' program
>.. try putting an explicit path to gzip in your program .. get the explicit
>path in what I guess is a *nix system with
>
>   which gzip
>
>on the command line
>
>alternatively there's an Archive::Zip module on CPAN that will allow you to
>do the zipping in Perl
>
>   http://search.cpan.org/search?dist=Archive-Zip
>
>--
>   jason king
>
>   A Canadian law states that citizens may not publicly remove bandages.
>   - http://dumblaws.com/




Is there an ODBC module in perl ?

2001-05-01 Thread Perl Programmer

Is there an ODBC module in perl ?

Thanks




Perl and NT

2001-05-01 Thread Matt Blatchley

Does anyone know of a way to use perl and CGI to have the following:

html page w/ form to get stdin from the user for username and
password.(basic),
pass the variables to the perl script which then modifies permissions for a
specific folder on NT
and allows the user to then have access to a particular folder after having
the password emailed to the user...
...which in my opionon is a security risk in itself, but that's the way
clients want it.

For some reason I tend to think VB script might be able to itany
suggestions would be helpful.

Matt

 





Re: Strange chop behaviour

2001-05-01 Thread Craig Moynes/Markham/IBM



-
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]



   

"Stephen P.

Potter"  To: Craig Moynes/Markham/IBM@IBMCA

<[EMAIL PROTECTED]   cc: [EMAIL PROTECTED], 
[EMAIL PROTECTED]
i.org>   Subject: Re: Strange chop behaviour   

   

05/01/01 01:39 

PM 

   

   





|Always check the return status of your opens.
I did not check the return status because it was a sample program and was
only for demonstration in here.

|| while ( !eof(ERR) )
|| $in = ;

|You are mixing things here you don't want to mix.  This should just be:

|while ($in = ) {

|You *can* mix these, but there is no real reason to.  Especially not in
|your sample code.

Why don't I want to mix these ?

I use chop when I know that each line will terminate with a newline
character.  If I were to use chomp I would require checks to make sure the
record seperator was set to what I expected.


|What version are you using.  This is not the output I get if I use the
|first two lines as the input file (scp_err).  My output looks like what
I'd
|expect:

I am using AIX.  It was placing an additional control character on the end
of the first line.  This has neven happened to me before reading the output
of commands from a file so I suspect it has something to do with scp.  But
I could be wrong.  I imagine the strange character was causing havoc with
print statements.


Thanks for your suggestions.





Re: Strange chop behaviour

2001-05-01 Thread Stephen P. Potter

Lightning flashed, thunder crashed and "Craig Moynes/Markham/IBM" <[EMAIL PROTECTED]
bm.com> whispered:
| open ( ERR, ";

You are mixing things here you don't want to mix.  This should just be:

while ($in = ) {

You *can* mix these, but there is no real reason to.  Especially not in
your sample code.

| chop $in;

chop indiscriminately removes the final character of the string.  Your best
option is to use chomp which only removes the end of record separator (if
it exists).

| ssh: HOST: Host not found
| lost connection
| lost connectionHOST: Host not found

What version are you using.  This is not the output I get if I use the
first two lines as the input file (scp_err).  My output looks like what I'd
expect:

ssh: HOST: Host not found
lost connection
Message - ssh: HOST: Host not foundlost connection




Re: writing an array to file

2001-05-01 Thread Stephen P. Potter

Lightning flashed, thunder crashed and "Kaustav Bhattacharya"  whispered:
|   open(BOOT_FILES,">boot_files.txt");
|   print BOOT_FILES @FILES;
|   close BOOT_FILES;

You should always check the return of open and close...

open BOOT_FILES, ">boot_files.txt" or die "Can't open boot_files: $!\n";
print BOOT_FILES @FILES;
close BOOT_FILES or die "Can't close boot_files: $!\n";

While we're at it, your subroutine doesn't contain a loop, but you are
pushing the line into an array.  Then opening the file, writing the array
(a single item) then closing the file.  That's a lot of opens, writes, and
closes.  You really only need a single open and close.

-sp



Re: Strange chop behaviour

2001-05-01 Thread Stephen P. Potter

Lightning flashed, thunder crashed and "Collin Rogowski" <[EMAIL PROTECTED]> w
hispered:
| They exist both.
| chop removes the last character.
| chomp removes the last character if it's newline.

Let's get this straight and correct.  chomp removes the input record
separator ($/).  This may or may not be a newline.

| Maybe your file has DOS-Newlines which are to characters (\r\n).
| If you chop, you keep \r at the end which could mess around with
| printing it. Perhaps you should try a double chop or something
| more sophisticated like:

chomp should handle this case correctly.

| $string =~ s/[^\da-ZA-Z-_]*$//;

That's ugly.  Especially as it could be much more cleanly written as
s/(\D\W)+$//.  \D is a non-digit, \W is a non-word character.  Also, use +
instead of *.  It's a little performance enhancer.  * can match nothing, so
you could end up replacing nothing with nothing.  + must match at least a
single character, so if there's nothing to replace, nothing happens.

-spp



finding common records between two files

2001-05-01 Thread Stussie, Mike

Hi all,

I'm a newbie to perl and trying to solve a problem.. Here is what I'm 
trying to do:

read thru flat file 'A' that looks something like this:(fields delimited by
'::')
BCSNDTJN::Joe User::1 N.
Main::Anytown::MO::None::None::None::Unknown::[EMAIL PROTECTED]

and find any duplicates based on the email address that might be in flat
file 'B'.
I want to take the duplicates and output it to another file so that I can
administer it later.

I found something in the camel book relating to hashes that might do the
trick but how do I get the flat file into a hash.




Any guidance or examples would be greatly appreciated.

Regards,
Mike Stussie


***
WARNING:  All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.
***



Re: Outputting content to the web

2001-05-01 Thread Dale Owens

I feel really stupid now.  Yes, I have been forgetting the leading / on the
path to perl.  After using #!/usr/bin/perl at the top of the script it
worked fine.

I want to add that I appreciate all the replies to my question.  I have used
the internet for a lot of years and have belonged to many mailing lists and
subscribed to countless newsgroups. Not one has ever been this responsive.
On top of that, none of the replies made me feel like an idiot for asking my
question.

Thanks,

Dale

- Original Message -
From: Timothy Kimball <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, May 01, 2001 11:32 AM
Subject: Re: Outputting content to the web


>
> : #!usr/bin/perl
>
> Shouldn't this be
>
>   #!/usr/bin/perl
>
> -- tdk




Question on optimizing this sub (help!)

2001-05-01 Thread Shawn

Can someone look at a subroutine for me? Specifically, after
this (at bottom of email) subroutine runs, it increases my
RSS by 6 megs, and shouldn't do that. (here it has indexed
133798 files)

This is the program before the checkstuff subroutine runs:
  PID USER PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
16370 root  -1 -20 94732  92M  1292 S <   0.0 26.8   0:54 ldir.pl

Here it is after the checkstuff subroutine runs:
  PID USER PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
16370 root   9 -20 98.5M  98M  1292 S <   0.0 28.5   1:07 ldir.pl

Here is some data about what the subroutine is doing:
There are two main indexes for file system data I have
in memory:

%{$files} is a hash of hashes of hashes of
arrays. @{ ${$files}{dirname}{basename} } is a list
of some stat data and an md5sum. (md5,dev,ino,siz,mtime)

%{$sums} is a hash of hashes of hashes hashes that serves
to cross reference the md5sum to the file itself. Quite
simply, ${$sums}{sum}{dir}{file} = 0 and then I can find
out which files have a certain md5sum, and access their
stat data by going to the other hash (%{$files}) which is
indexed by dir and file.

checkstuff does simple sanity checking by walking the hashes
and counting elements. What is wrong with it???


... 
print "Ok, now check my mem usage!\n";
$temp=;
checkstuff();
print "Ok, now check my mem usage!\n";
$temp=;

sub checkstuff {
my $temp=0;
my $temp2=0;
my $sum;
my $ref;
my $dir;
my $file;
my @files;
my @dirs;
my $name="checkstuff";
foreach $sum (sort keys %{$sums}) {
@dirs=(sort keys %{ ${$sums}{$sum} });
foreach $dir (@dirs) {
@files=(keys %{ ${$sums}{$sum}{$dir} });
$temp += $#files+1;
}
}
foreach $dir (sort keys %{$dirs}) {
foreach $file (sort keys %{ ${$dirs}{$dir} }) {
$temp2++;
}
}
print "\t$name -> MD5sums($temp) FileDirs($temp2)\n";
undef $temp;
undef $temp2;
undef $sum;
undef $ref;
undef $dir;
undef $file;
undef @files;
undef @dirs;
undef $name;
return();
}


--
Hob Goblin
[EMAIL PROTECTED]

"Look into my nipples of the future..." -Really Really Big Man



writing an array to file

2001-05-01 Thread Kaustav Bhattacharya

I have an array populated with data, I want to dump its content to file but
my following code is not writing any data out! HELP:

sub wanted {
@FILES = ();
if ( $File::Find::name =~ /_boot\.js$/ )
{
   push @FILES, "$File::Find::name\n";
}

print (@FILES);

open(BOOT_FILES,">boot_files.txt");
print BOOT_FILES @FILES;
close BOOT_FILES;
}


Kaustav




Re: open file, find lines and print to a second file....

2001-05-01 Thread Gil Tucker [ateliermobile]





hello world









- Original Message -
From: McCormick, Rob E <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 30, 2001 11:10 PM
Subject: open file, find lines and print to a second file


> gang,
>
> # problem:  open a file
> # find lines that meet a condition, put them in an output file
>
> Could you share some patterns/sample code that you use to accomplish this
> task?  What pattern do you use when the output file doesn't exist when the
> script begins?
>
> The code below errors with:
> C:\WINNT\Profiles\rem27920\Desktop\perl>remove_lines.pl
> syntax error at C:\WINNT\Profiles\rem\Desktop\perl\remove_lines.pl line 7,
> near ", >"
> Execution of C:\WINNT\Profiles\rem\Desktop\perl\remove_lines.pl aborted
due
> to compilation
> errors.
>
> #!c:/perl/bin/perl -w
> use strict;
>
> my $file = 'c:/winnt/profiles/rem/desktop/old_websites.txt';
> my $outfile = 'c:/winnt/profiles/rem/desktop/old_web2.txt';
> open(INFO, "$file") or die "$!"; # file open w/error check
> open(RESULT, >$outfile);  # tried "$outfile" as well...
> my @lines = grep { ! /_vti_cnf/ } ;
> while () {
> print RESULT;
> }
>
> #print (@lines, $outfile );  # prints lines to STDOUT, and the filename
> # print (join "\n", @lines);  # print files, one per line
>
> close INFO;
> close RESULT;
>
> thank you,
> Rob
> --
> Rob McCormick
> [EMAIL PROTECTED]
>
>




RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan

Thank you so much for your help Gary and Jason. I tried the following and it
works perfectly.

Patrick

#!c:/perl/bin/perl -w
use strict;
my %tracks=(); # create empty hash

$tracks{'test'}->{artist}='test_artist';
$tracks{'test'}->{title}='test_title';
$tracks{'test2'}->{artist}='test_artist2';
$tracks{'test2'}->{title}='test_title2';

for my $row ( keys %tracks ) {
my $artist = $tracks{$row}->{artist};
my $title  = $tracks{$row}->{title};
print '\$row=', $row, "\n", '\$artist=', $artist, "\n", '\$title=', $title,
"\n";
}




Re: Outputting content to the web

2001-05-01 Thread Steve Neu

Mr. Owens,

I find that the best way to write CGI scripts is to write them and run
them on the command line.  Then, when I know that they run without errors, I
put them on my web server.
If you do this, you can also specify...
#!/usr/bin/perl -w
(with the -w on the end) to get more information.  This will assure you
that your problem is not in your script, but somewhere else.
Also, are you running a web server on your computer?  Your statement,
"...providing the full path to it in the address bar of my browser..." makes
me think you are not.  Otherwise you would say something like
"http://localhost/directory/script.pl"; (on a windows box, anyway).

Also, I believe you might find the CGI:Carp module interesting.
"perldoc CGI::Carp"

Stephen Neu
Internet Development
Characterlink.net
(630) 323-9800 ext. 235

"What is so difficult for developers to accept sometimes is that there
already is a standard, and they didn't write it."
   --Steve Neu





RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan

Opps, forgot to change the variable name. Ah the power of cut and paste...

 for my $row ( keys %tracks ) {
$artist = $tracks{$row}->{artist};
$title  = $tracks{$row}->{title};
 }

> I wrote:
> 
> Excellent! Thanks! So, when I need to iterate through the hash of 
> hashes and
> work on the data would I do this:
> 
> for my $row ( keys %tracks ) {
>   $artist = $tracks{$fname}->{artist};
>   $title  = $tracks{$fname}->{title};
> }
> 
> Thanks again for the pointer,
> Patrick
> 
> > Gary Stainburn wrote:
> >
> > Surely, a hash of hashes would be better then.
> >
> > my %tracks=(); # create empty hash
> >
> > Then to populate the data you do something like:
> >
> > $tracks{$fname}->{artist}=$artist;
> > $tracks{$fname}->{title}=$title;
> >
> > Gary
> >
> > On Tuesday 01 May 2001  4:08 pm, J. Patrick Lanigan wrote:
> > > Overall what I am trying to accomplish is to loop through a bunch of
> > > mp3 files and extract the ID3 Tag Info into a hash (%tracks) for
> > > which each key references the filename, filepath, artist, album,
> > > tracknum, title, genre for one file. Once I have %tracks populated I
> > > need to iterate through it and INSERT the info into a PostgreSQL DB.
> > > I am completely open to any other suggestion for a way to collect a
> > > dataset with a unique identifier. I've got all the other code
> > > working, this is the last piece to my puzzel.
> > >
> > > Thanks,
> > > Patrick




Re: Outputting content to the web

2001-05-01 Thread Gary Stainburn

Hi Dale,

When this script fails, it's usually a server configuration problem, 
which is not really on-topic here, but.

1) what do you mean by full path? bear in mind that the path you 
specify in the URL will get munged by the web server.

2) what error does the browser show you? permissions, file not found, 
or does it simply show you the text of your script.

3) what gets written to the log files on the web server?  This is 
usually the best place to start.

Do a bit more investigating, and try reading the FAQ for your server.

Gary

On Tuesday 01 May 2001  4:28 pm, Dale Owens wrote:

> > Hello,
>
> I am completely new to perl and this question may seem really lame,
> but I can't get the most basic script to work.  I am trying to run
> this on my web host's server:
>
> #!usr/bin/perl
>
> print "Content-type: text/html\n\n";
> print "Hello World!\n";
>
> I then try to access the script by providing the full path to it in
> the address bar of my browser.  I have set the mode of the above file
> to 755 and am using the proper path to perl according the the web
> host.  I have written a perl script to handle form input, but if I
> can't get the above to work, the form processor is useless.  Is this
> a problem with the web host or am I missing something in the way I am
> trying to output content to the web page?
>
> Dale

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 




RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan

Excellent! Thanks! So, when I need to iterate through the hash of hashes and
work on the data would I do this:

for my $row ( keys %tracks ) {
$artist = $tracks{$fname}->{artist};
$title  = $tracks{$fname}->{title};
}

Thanks again for the pointer,
Patrick

> Gary Stainburn wrote:
>
> Surely, a hash of hashes would be better then.
>
> my %tracks=(); # create empty hash
>
> Then to populate the data you do something like:
>
> $tracks{$fname}->{artist}=$artist;
> $tracks{$fname}->{title}=$title;
>
> Gary
>
> On Tuesday 01 May 2001  4:08 pm, J. Patrick Lanigan wrote:
> > Overall what I am trying to accomplish is to loop through a bunch of
> > mp3 files and extract the ID3 Tag Info into a hash (%tracks) for
> > which each key references the filename, filepath, artist, album,
> > tracknum, title, genre for one file. Once I have %tracks populated I
> > need to iterate through it and INSERT the info into a PostgreSQL DB.
> > I am completely open to any other suggestion for a way to collect a
> > dataset with a unique identifier. I've got all the other code
> > working, this is the last piece to my puzzel.
> >
> > Thanks,
> > Patrick
> >
> > > Jason King wrote:
> > >
> > > J. Patrick Lanigan writes ..
> > >
> > > >I haven't quite sorted out the more complex data structure in perl
> > > > yet. Anyhow, I need to take the following hash of arrays...
> > >
> > > you have some very confusing code there .. so let's do it one bit
> > > at a time
> > >
> > > >my %tracks = ();
> > >
> > > create a hash called tracks with zero elements
> > >
> > > >push @{$tracks{$filename}},
> > > > $_, # tracks.filename
> > > >
> > > > $File::Find::dir . '/', # tracks.filepath
> > > > $artist,# artist.artist_name
> > > > $album, # album.title
> > > > $tracknum,  # tracks.track_num
> > > > $title, # tracks.title
> > > > $genre; # tracks.title
> > >
> > > create a new element of the tracks hash using the value of the
> > > variable $filename as the key
> > >
> > > treat that new element as an array reference and push a bunch of
> > > values onto
> > > it
> > >
> > > assume for a secont that $filename has the value 'file1' .. at
> > > this point in
> > > the code you have something like the following structure
> > >
> > >   %tracks = ( file1 => [ $_, 'some/path/', 'artist_name', 'etc...'
> > > ] );
> > >
> > > I didn't continue it .. but as well as the artist name you've got
> > > the album
> > > title, the track number, title, and genre in there .. you get the
> > > drift
> > >
> > > but you've got only one member of the %tracks hash .. it's key is
> > > the value
> > > of $filename and it's value is an array reference as above
> > >
> > > >for my $row ( keys %tracks ){
> > >
> > > so now we grab the keys of %tracks - of which there is only one -
> > > 'file1' in
> > > our example .. then we stick that into $row
> > >
> > > > (my $qualified_filename, my $filename, my $filepath,
> > > >$artist, $album, $tracknum, $title, $genre) =
> > > >"$row @{ $tracks{$row} }";
> > >
> > > now we create a string containing the key ('file1') then a space
> > > and then the values of the array referred to by $tracks{file1}
> > >
> > > it's a single value - so it goes into the first element of the
> > > lvalue list -
> > > ie. $qualified_filename
> > >
> > > the following code would have done EXACTLY the same as what you've
> > > done above
> > >
> > >   my %tracks;
> > >
> > >   $tracks{$filename} = [ $_,
> > >  $File::Find::dir . '/',
> > >  $artist,
> > >  $album,
> > >  $tracknum,
> > >  $title,
> > >  $genre,
> > >];
> > >
> > >   my $qualified_name = "$filename @{ $tracks{$filename} }";
> > >
> > > so .. as you can tell - you'll have to explain a bit more about
> > > what you're
> > > trying to do .. because it's really not clear
> > >
> > > --
> > >   jason king
> > >
> > >   A Canadian law states that citizens may not publicly remove
> > > bandages. - http://dumblaws.com/
>
> --
> Gary Stainburn
>
> This email does not contain private or confidential material as it
> may be snooped on by interested government parties for unknown
> and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
>




Re: Outputting content to the web

2001-05-01 Thread Timothy Kimball


: #!usr/bin/perl

Shouldn't this be

  #!/usr/bin/perl

-- tdk



Re: Outputting content to the web

2001-05-01 Thread John Joseph Trammell

On Tue, May 01, 2001 at 11:28:02AM -0400, Dale Owens wrote:
> I am completely new to perl and this question may seem really lame,
> but I can't get the most basic script to work.  I am trying to run
> this on my web host's server:
> 
> #!usr/bin/perl
> 
> print "Content-type: text/html\n\n";
> print "Hello World!\n";

One clue is that you should be able to run these scripts from
the command line as well:

[ ~/test/cgi-01 ] cat foo.pl
#!usr/bin/perl

print "Content-type: text/html\n\n";
print "Hello World!\n";

[ ~/test/cgi-01 ] chmod 755 foo.pl
[ ~/test/cgi-01 ] ./foo.pl
./foo.pl: Command not found.
[ ~/test/cgi-01 ]

Your problem is that your shebang line should be "#!/usr/bin/perl".
Attention to detail!

-- 
If the organizational structure is threatening in any way, nothing is
going to be documented until it is completely defensible.
- F. Brooks, _The Mythical Man-Month_



Re: IF statements

2001-05-01 Thread Stephen P. Potter

There isn't a switch statement either.  There's a way to make something
that looks similar to a switch, but it isn't a builtin control structure.

-spp

Lightning flashed, thunder crashed and "Kaustav Bhattacharya"  whispered:
| Mark,
| I only recently started coding in PERL so don't take the following as
| official.
| 
| There is no CASE statement in PERL. Instead you use something called SWITCH.
| 
| The O'Reilly book has an example of how to use the SWITCH statement.



Re: IF statements

2001-05-01 Thread Stephen P. Potter

Lightning flashed, thunder crashed and Mark Martin <[EMAIL PROTECTED]> whisper
ed:
| What I have is this:
| 
| if ($variable == 02){
|   print OUT1 "$variable"; 
|   $lines1 ++;
| } elsif($variable == 03){
|   print OUT1 "$variable\n"; 
|   $lines2 ++;
| } elsif($variable == "08"){
|   print OUT1 "$variable\n"; 
|   $lines2 ++;
| }  elsif($variable == 79){
|   print OUT3 "$variable\n"; 
|   $lines3 ++;
| }  elsif($variable == 93){
|   print OUT3 "$variable\n"; 
|   $lines3 ++;
| }  elsif($variable == 99){
|   print OUT3 "$variable\n"; 
|   $lines3 ++;
| }
| 
| So I need to shorten that to if (variable == "02" OR "03" OR "08"){ .etc
| 
| I think what I need is something called a case. but I can't find the syntax
| anywhere.

Perl doesn't have a case statement.  I'm confused a little by what you want
to do.  You say you want to shorten it to "02" or "03" or "08", but the
body of the loop is different for those.  It is the same for the 79, 93,
and 99, though.  You are also mixing numeric ( == ) with strings.  What
exactly are you trying to do, there are several options depending.

You might be interested in using hashes or arrays to hold your counters and
output file handles.  Then you could reduce the whole if thing to two lines.
For example, something like:

%FH = ( 02 => "OUT1",
03 => "OUT1",
09 => "OUT1",
79 => "OUT3",
93 => "OUT3",
99 => "OUT3"
  );
%count = ( 02 => 1,
   03 => 2,
   08 => 2,
   79 => 2,
   93 => 3,
   99 => 3
 );

print { $FH{$variable} } "$variable\n";
$lines[$count{$variable}]++;

-spp



Re: IF statements

2001-05-01 Thread Timothy Kimball


: I think what I need is something called a case. but I can't find the syntax
: anywhere.

Perl doesn't have an official case (that is, switch) statement, but
there is a Switch.pm module available on CPAN. Here's the synopsis from
its manpage:

use Switch;

switch ($val) {
case 1  { print "number 1" }
case "a"{ print "string a" }
case [1..10,42] { print "number in list" }
case (@array)   { print "number in list" }
case /\w+/  { print "pattern" }
case qr/\w+/{ print "pattern" }
case (%hash){ print "entry in hash" }
case (\%hash)   { print "entry in hash" }
case (\&sub){ print "arg to subroutine" }
else{ print "previous case not true" }
}

It's a very powerful tool (though I found that use'ing it introduces a
start-up latency which could be bad for straight CGI scripts).

There are several other ways to do things like this (otherwise it
wouldn't be Perl;) See the Camel, 2nd ed pg 104 or 3rd ed pg 124 for
more about this.

-- tdk



Outputting content to the web

2001-05-01 Thread Dale Owens

Hello,

I am completely new to perl and this question may seem really lame, but I can't get 
the most basic script to work.  I am trying to run this on my web host's server:

#!usr/bin/perl

print "Content-type: text/html\n\n";
print "Hello World!\n";

I then try to access the script by providing the full path to it in the address bar of 
my browser.  I have set the mode of the above file to 755 and am using the proper path 
to perl according the the web host.  I have written a perl script to handle form 
input, but if I can't get the above to work, the form processor is useless.  Is this a 
problem with the web host or am I missing something in the way I am trying to output 
content to the web page?

Dale



Re: traversing dir tree and reading in files

2001-05-01 Thread Craig Moynes/Markham/IBM

Wanted is where you want to change this.  Within the function place a
regular expression or file-test ...anything that will give you a true/false
answer that you can use.

To get a list of executable files you would change

>sub wanted {
>  print "$File::Find::name\n";
>}

to:

sub wanted {
 if ( -x "$File::Find::name" )
 {
   print "$File::Find::name\n";
 }
}
This test the filename passed and prints out the result.  You can change
the print statement to add the filename to a array or hash, or perform and
open on the file, whatever you want.

For your case this should work:
_boot.js


my (@FILES);

sub wanted {
 if ( $File::Find::name =~ /_boot\.js$/ )
 {
   push @FILES, "$File::Find::name";
 }
}

This will add any filename that ends with _boot.js to the array FILES.
When declaring the FILES array do not use:
@FILES = "";
This will place a blank line within your array and may cause problems later
(massive problems for me :).

Have fun,


-
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]



   

"Kaustav   

Bhattacharya"To: <[EMAIL PROTECTED]>  

   Subject: traversing dir tree and reading 
in files 
   

05/01/01 10:39 

AM 

Please respond 

to kaustav 

   

   




been trying to work out how to get PERL to traverse a given directory tree
looking for all files with the string _boot.js in the file name. then I
want
to read each file and find all lines which start with the string "sWinReg"
and copy them in to an array with each line being places in a seperate cell
in the array.  So far I have written some code to run down the directory
tree which looks like this:

use File::Find;
find(\&wanted, 'D:\\app\\pages\\services\');

sub wanted {
   print "$File::Find::name\n";
}

this lists all the files in the given path, but I can't work out how to
list
only files which contain "_boot.js" in the file name. I only want those
files and none of the others.and how would I put each line outputted in to
an array? Do a "foreach" and "push" each item in to the array as it's read
in from the FS?

Any pointers on how to do this?

Kaustav
--
Kaustav Bhattacharya
[EMAIL PROTECTED]
Mobile: +44 (0)771 421 6919








Re: Hash of Arrays Question

2001-05-01 Thread Gary Stainburn

Surely, a hash of hashes would be better then.

my %tracks=(); # create empty hash

Then to populate the data you do something like:

$tracks{$fname}->{artist}=$artist;
$tracls{$fname}->{title}=$title;

Gary

On Tuesday 01 May 2001  4:08 pm, J. Patrick Lanigan wrote:
> Overall what I am trying to accomplish is to loop through a bunch of
> mp3 files and extract the ID3 Tag Info into a hash (%tracks) for
> which each key references the filename, filepath, artist, album,
> tracknum, title, genre for one file. Once I have %tracks populated I
> need to iterate through it and INSERT the info into a PostgreSQL DB.
> I am completely open to any other suggestion for a way to collect a
> dataset with a unique identifier. I've got all the other code
> working, this is the last piece to my puzzel.
>
> Thanks,
> Patrick
>
> > Jason King wrote:
> >
> > J. Patrick Lanigan writes ..
> >
> > >I haven't quite sorted out the more complex data structure in perl
> > > yet. Anyhow, I need to take the following hash of arrays...
> >
> > you have some very confusing code there .. so let's do it one bit
> > at a time
> >
> > >my %tracks = ();
> >
> > create a hash called tracks with zero elements
> >
> > >push @{$tracks{$filename}},
> > >   $_, # tracks.filename
> > >
> > >   $File::Find::dir . '/', # tracks.filepath
> > >   $artist,# artist.artist_name
> > >   $album, # album.title
> > >   $tracknum,  # tracks.track_num
> > >   $title, # tracks.title
> > >   $genre; # tracks.title
> >
> > create a new element of the tracks hash using the value of the
> > variable $filename as the key
> >
> > treat that new element as an array reference and push a bunch of
> > values onto
> > it
> >
> > assume for a secont that $filename has the value 'file1' .. at
> > this point in
> > the code you have something like the following structure
> >
> >   %tracks = ( file1 => [ $_, 'some/path/', 'artist_name', 'etc...'
> > ] );
> >
> > I didn't continue it .. but as well as the artist name you've got
> > the album
> > title, the track number, title, and genre in there .. you get the
> > drift
> >
> > but you've got only one member of the %tracks hash .. it's key is
> > the value
> > of $filename and it's value is an array reference as above
> >
> > >for my $row ( keys %tracks ){
> >
> > so now we grab the keys of %tracks - of which there is only one -
> > 'file1' in
> > our example .. then we stick that into $row
> >
> > >   (my $qualified_filename, my $filename, my $filepath,
> > >$artist, $album, $tracknum, $title, $genre) =
> > >"$row @{ $tracks{$row} }";
> >
> > now we create a string containing the key ('file1') then a space
> > and then the values of the array referred to by $tracks{file1}
> >
> > it's a single value - so it goes into the first element of the
> > lvalue list -
> > ie. $qualified_filename
> >
> > the following code would have done EXACTLY the same as what you've
> > done above
> >
> >   my %tracks;
> >
> >   $tracks{$filename} = [ $_,
> >  $File::Find::dir . '/',
> >  $artist,
> >  $album,
> >  $tracknum,
> >  $title,
> >  $genre,
> >];
> >
> >   my $qualified_name = "$filename @{ $tracks{$filename} }";
> >
> > so .. as you can tell - you'll have to explain a bit more about
> > what you're
> > trying to do .. because it's really not clear
> >
> > --
> >   jason king
> >
> >   A Canadian law states that citizens may not publicly remove
> > bandages. - http://dumblaws.com/

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 




Re: IF statements

2001-05-01 Thread Gary Stainburn

Hi Mark,

Try this:

switch:for ($variable) { #put $variable into $_
  (/02/ || /03/ || /08/) && do {
  print OUT1 "$variable\n";
  $lines1++;
  last; } ;
  (/79/ || /93/ || /99/) && do {
  print OUT3 "$variable\n";
  $lines3++;
  last; } ;
}

Using this code, if the bit before the && is true, i.e. one of the 
regular expressions is true, then it evaluates (does) the bit after the 
&&.

Gary
On Tuesday 01 May 2001  4:54 pm, Mark Martin wrote:
> What I have is this:
>
> if ($variable == 02){
>   print OUT1 "$variable";
>   $lines1 ++;
> } elsif($variable == 03){
>   print OUT1 "$variable\n";
>   $lines2 ++;
> } elsif($variable == "08"){
>   print OUT1 "$variable\n";
>   $lines2 ++;
> }  elsif($variable == 79){
>   print OUT3 "$variable\n";
>   $lines3 ++;
> }  elsif($variable == 93){
>   print OUT3 "$variable\n";
>   $lines3 ++;
> }  elsif($variable == 99){
>   print OUT3 "$variable\n";
>   $lines3 ++;
> }
>
> So I need to shorten that to if (variable == "02" OR "03" OR "08"){
> .etc
>
> I think what I need is something called a case. but I can't find the
> syntax anywhere.
> Cheers.
> _
>
> Mark Martin
> Computer Centre
> National University of Ireland Maynooth
>
> Tel: (01)708 4716/3830
> Fax: (01)628 6249

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 




RE: IF statements

2001-05-01 Thread Kaustav Bhattacharya

Mark,
I only recently started coding in PERL so don't take the following as
official.

There is no CASE statement in PERL. Instead you use something called SWITCH.

The O'Reilly book has an example of how to use the SWITCH statement.

Kaustav

> -Original Message-
> From: Mark Martin [mailto:[EMAIL PROTECTED]]
> Sent: 01 May 2001 16:55
> To: [EMAIL PROTECTED]
> Subject: IF statements
>
>
> What I have is this:
>
> if ($variable == 02){
>   print OUT1 "$variable";
>   $lines1 ++;
> } elsif($variable == 03){
>   print OUT1 "$variable\n";
>   $lines2 ++;
> } elsif($variable == "08"){
>   print OUT1 "$variable\n";
>   $lines2 ++;
> }  elsif($variable == 79){
>   print OUT3 "$variable\n";
>   $lines3 ++;
> }  elsif($variable == 93){
>   print OUT3 "$variable\n";
>   $lines3 ++;
> }  elsif($variable == 99){
>   print OUT3 "$variable\n";
>   $lines3 ++;
> }
>
> So I need to shorten that to if (variable == "02" OR "03" OR
> "08"){ .etc
>
> I think what I need is something called a case. but I can't find
> the syntax
> anywhere.
> Cheers.
> _
>
> Mark Martin
> Computer Centre
> National University of Ireland Maynooth
>
> Tel: (01)708 4716/3830
> Fax: (01)628 6249
>
>




RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan

Overall what I am trying to accomplish is to loop through a bunch of mp3
files and extract the ID3 Tag Info into a hash (%tracks) for which each key
references the filename, filepath, artist, album, tracknum, title, genre for
one file. Once I have %tracks populated I need to iterate through it and
INSERT the info into a PostgreSQL DB. I am completely open to any other
suggestion for a way to collect a dataset with a unique identifier. I've got
all the other code working, this is the last piece to my puzzel.

Thanks,
Patrick


> Jason King wrote:
>
> J. Patrick Lanigan writes ..
>
>
> >I haven't quite sorted out the more complex data structure in perl yet.
> >Anyhow, I need to take the following hash of arrays...
>
>
> you have some very confusing code there .. so let's do it one bit
> at a time
>
>
> >my %tracks = ();
>
> create a hash called tracks with zero elements
>
>
> >push @{$tracks{$filename}},
> > $_, # tracks.filename
>
> > $File::Find::dir . '/', # tracks.filepath
> > $artist,# artist.artist_name
> > $album, # album.title
> > $tracknum,  # tracks.track_num
> > $title, # tracks.title
> > $genre; # tracks.title
>
> create a new element of the tracks hash using the value of the variable
> $filename as the key
>
> treat that new element as an array reference and push a bunch of
> values onto
> it
>
> assume for a secont that $filename has the value 'file1' .. at
> this point in
> the code you have something like the following structure
>
>   %tracks = ( file1 => [ $_, 'some/path/', 'artist_name', 'etc...' ] );
>
> I didn't continue it .. but as well as the artist name you've got
> the album
> title, the track number, title, and genre in there .. you get the drift
>
> but you've got only one member of the %tracks hash .. it's key is
> the value
> of $filename and it's value is an array reference as above
>
>
> >for my $row ( keys %tracks ){
>
> so now we grab the keys of %tracks - of which there is only one -
> 'file1' in
> our example .. then we stick that into $row
>
> > (my $qualified_filename, my $filename, my $filepath,
> >$artist, $album, $tracknum, $title, $genre) =
> >"$row @{ $tracks{$row} }";
>
> now we create a string containing the key ('file1') then a space and then
> the values of the array referred to by $tracks{file1}
>
> it's a single value - so it goes into the first element of the
> lvalue list -
> ie. $qualified_filename
>
> the following code would have done EXACTLY the same as what you've done
> above
>
>   my %tracks;
>
>   $tracks{$filename} = [ $_,
>  $File::Find::dir . '/',
>  $artist,
>  $album,
>  $tracknum,
>  $title,
>  $genre,
>];
>
>   my $qualified_name = "$filename @{ $tracks{$filename} }";
>
> so .. as you can tell - you'll have to explain a bit more about
> what you're
> trying to do .. because it's really not clear
>
> --
>   jason king
>
>   A Canadian law states that citizens may not publicly remove bandages.
>   - http://dumblaws.com/




IF statements

2001-05-01 Thread Mark Martin

What I have is this:

if ($variable == 02){
print OUT1 "$variable"; 
$lines1 ++;
} elsif($variable == 03){
print OUT1 "$variable\n"; 
$lines2 ++;
} elsif($variable == "08"){
print OUT1 "$variable\n"; 
$lines2 ++;
}  elsif($variable == 79){
print OUT3 "$variable\n"; 
$lines3 ++;
}  elsif($variable == 93){
print OUT3 "$variable\n"; 
$lines3 ++;
}  elsif($variable == 99){
print OUT3 "$variable\n"; 
$lines3 ++;
}

So I need to shorten that to if (variable == "02" OR "03" OR "08"){ .etc

I think what I need is something called a case. but I can't find the syntax
anywhere.
Cheers.
_

Mark Martin
Computer Centre
National University of Ireland Maynooth

Tel: (01)708 4716/3830
Fax: (01)628 6249



traversing dir tree and reading in files

2001-05-01 Thread Kaustav Bhattacharya

been trying to work out how to get PERL to traverse a given directory tree
looking for all files with the string _boot.js in the file name. then I want
to read each file and find all lines which start with the string "sWinReg"
and copy them in to an array with each line being places in a seperate cell
in the array.  So far I have written some code to run down the directory
tree which looks like this:

use File::Find;
find(\&wanted, 'D:\\app\\pages\\services\');

sub wanted {
print "$File::Find::name\n";
}

this lists all the files in the given path, but I can't work out how to list
only files which contain "_boot.js" in the file name. I only want those
files and none of the others.and how would I put each line outputted in to
an array? Do a "foreach" and "push" each item in to the array as it's read
in from the FS?

Any pointers on how to do this?

Kaustav
--
Kaustav Bhattacharya
[EMAIL PROTECTED]
Mobile: +44 (0)771 421 6919




Re: Problem with reading string

2001-05-01 Thread Greg Meckes

In your statements:
print "@zin[$i] \n\r";

You should use:
print "$zin[$i] \n\r";

And:
> $ta = @zin[6];
> $tb = @zin[7];
> $tc = @zin[8];
> $td = @zin[9];

should be:

> $ta = $zin[6];
> $tb = $zin[7];
> $tc = $zin[8];
> $td = $zin[9];

And:
if (@zin[$t] = /212.104.202.50/g) {

Should be:
if ($zin[$t] =~ /212.104.202.50/g) {
Or:
if ($zin[$t] eq "212.104.202.50") {

Hope this helps,
Greg

__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: Strange chop behaviour

2001-05-01 Thread Collin Rogowski

They exist both.
chop removes the last character.
chomp removes the last character if it's newline.

To the original problem:

I had a similar problem once.
Maybe your file has DOS-Newlines which are to characters (\r\n).
If you chop, you keep \r at the end which could mess around with
printing it. Perhaps you should try a double chop or something
more sophisticated like:

$string =~ s/[^\da-ZA-Z-_]*$//;

That means remove all on digit (0-9), non word (a-z,A-Z,_-) at the end
of the string.

Please keep in mind that this a bit of a shot in the dark.
So do not:

change code;
sell to customer without testing for big $$$;
call lawyer;
sue collin;

;-)

cr


On Tue, 01 May 2001 09:03:13 -0400, Francis Henry said:

> Craig,
>  
>  I'm a newbie too, but isn't the function "chomp"?
>  
>  Francis
>  
>  Craig Moynes/Markham/IBM wrote:
>  
>  > A little background.  I am running an scp process within a perl script and
>  > redirecting the error to a file (scp_err).   I then read in the lines of
>  > this file and attempt to place them in an error string to log to syslog.
>  >
>  > Code Sample:
>  >
>  > #!/usr/bin/perl -w
>  > open ( ERR, "  > my ( $err_msg ) = "";
>  > while ( !eof(ERR) )
>  > {
>  > my ( $in ) = "";
>  > $in = ;
>  > chop $in;
>  > print "$in\n";
>  > $err_msg = $err_msg . $in;
>  > }
>  > print "Message - $err_msg\n";
>  >
>  > Now I have added a lot of extra print statements for debugging purposes.
>  >
>  > Sample Output:
>  > ssh: HOST: Host not found
>  > lost connection
>  > lost connectionHOST: Host not found
>  >
>  > The first two lines being each line in the scp_err file, and the last line
>  > being the final line.
>  >
>  > If I remove the chop then it works fine (except for the newline char that I
>  > want to remove).  If I replace the chop with a  s/\n$// then it gives the
>  > same output.
>  >
>  > Any ideas why this is occurring ?
>  > -
>  > Craig Moynes
>  > Internship Student
>  > netCC Development
>  > IBM Global Services, Canada
>  > Tel: (905) 316-3486
>  > [EMAIL PROTECTED]
>  
>  
>  




Re: Strange chop behaviour

2001-05-01 Thread Greg Meckes

chomp removes only the newline (what you want I think) and chop removes the last 
character
#instead of 
chop $in;
#Try:
chomp $in;

Greg


__
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/



Re: Problem with reading string

2001-05-01 Thread Collin Rogowski

I didn't quite get what your problem was.
Can you elaborate on that?
There are a couple of newbie problems in your script:




>  ##
>  #!/usr/bin/perl

You should say:

!/usr/bin/perl -w

This turns on warnings (which is very helpfull)
You should also say

use strict;

Than you have to declare all variables with 'my'. This helps
enormously with typos.

>  
>  for ($i=0;$i<20;$i++) {
> @zin[$i] = $ARGV[$i];
> print "@zin[$i] \n\r";
>  }

You can copy an array much easier:

my @zin = @ARGV;


>  
>  #print "@zin";
>  #$_ = $zin;
>  # $zin = $ARGV;
>  
>  print "$zin";

$zin is a new variable to perl. @zin is a totally seperate thing.
"use struct" would have argued with you about that ;-)

>  
>  $ta = @zin[6];
>  $tb = @zin[7];
>  $tc = @zin[8];
>  $td = @zin[9];

you only access the whole array by saying @arrayname. If you want to
access just one array-entry you say $arrayname[index]. I remember this
by thinking: $ is to acces a scalar. Elements of arrays are scalars.
So I use $ to acces the elemnt of an array.

>  
>  for ($t=0;$t<20;$t++) {
>  
>  if (@zin[$t] = /212.104.202.50/g) {
>  $name = "NS1.NETCASE.NL";
>  $email = '[EMAIL PROTECTED]';
>  $bericht ="Hoi wij krijgen de melding $ta $tb $tc $td van $name, kunnen 
>jullie hier iets aan doen?";
>  }

Here is the same problem with @zin. You want to say $zin[$t].
What you do here is assigning a regular expression to variable.
This is not what you want. You want to _match_ the regex against
the contents of a variable. You have to use the =~ operator to do that.
In the regex . is a special character meaning "any character". If
you want a literal dot (like in your IP) you have to backslash it
(\. instead of .).
correct line:

if ($zin[$t] =~ /212\.104\.202\.50/) {

You can leave out the g. It means global matching which does nothing in
this context.

You should correct the rest accordingly.




If you need further help,
feel free to ask again,

cr



Using Email

2001-05-01 Thread Phillip Bruce

Hi,

  Anyone with experience in having perl call up mailx and
  at the same time have the body of the messages sent along
  with attachment.

-- 

*** Phillip B. Bruce ***
*** http://pbbruce.home.mindspring.com   ***
*** [EMAIL PROTECTED]   ***
***  ***
*** "Have you ever noticed? Anybody going slower than***
*** you is an idiot, and anyone going faster than you*** 
*** is a maniac." - George Carlin***




Re: Strange chop behaviour

2001-05-01 Thread Francis Henry

Craig,

I'm a newbie too, but isn't the function "chomp"?

Francis

Craig Moynes/Markham/IBM wrote:

> A little background.  I am running an scp process within a perl script and
> redirecting the error to a file (scp_err).   I then read in the lines of
> this file and attempt to place them in an error string to log to syslog.
>
> Code Sample:
>
> #!/usr/bin/perl -w
> open ( ERR, " my ( $err_msg ) = "";
> while ( !eof(ERR) )
> {
> my ( $in ) = "";
> $in = ;
> chop $in;
> print "$in\n";
> $err_msg = $err_msg . $in;
> }
> print "Message - $err_msg\n";
>
> Now I have added a lot of extra print statements for debugging purposes.
>
> Sample Output:
> ssh: HOST: Host not found
> lost connection
> lost connectionHOST: Host not found
>
> The first two lines being each line in the scp_err file, and the last line
> being the final line.
>
> If I remove the chop then it works fine (except for the newline char that I
> want to remove).  If I replace the chop with a  s/\n$// then it gives the
> same output.
>
> Any ideas why this is occurring ?
> -
> Craig Moynes
> Internship Student
> netCC Development
> IBM Global Services, Canada
> Tel: (905) 316-3486
> [EMAIL PROTECTED]




Strange chop behaviour

2001-05-01 Thread Craig Moynes/Markham/IBM

A little background.  I am running an scp process within a perl script and
redirecting the error to a file (scp_err).   I then read in the lines of
this file and attempt to place them in an error string to log to syslog.

Code Sample:

#!/usr/bin/perl -w
open ( ERR, ";
chop $in;
print "$in\n";
$err_msg = $err_msg . $in;
}
print "Message - $err_msg\n";


Now I have added a lot of extra print statements for debugging purposes.

Sample Output:
ssh: HOST: Host not found
lost connection
lost connectionHOST: Host not found

The first two lines being each line in the scp_err file, and the last line
being the final line.

If I remove the chop then it works fine (except for the newline char that I
want to remove).  If I replace the chop with a  s/\n$// then it gives the
same output.

Any ideas why this is occurring ?
-
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]





Re: Got a project for Perl but need some help

2001-05-01 Thread Kenny Gatdula

Hi,
You may find the MacOSX list helpful. Here's the article announcing the list.
http://use.perl.org/article.pl?sid=01/03/29/1452216&mode=thread&threshold=

send a message to subscribe at [EMAIL PROTECTED]


At 05:32 AM 5/1/2001 -0400, you wrote:
>Hey guys,
>
>Thanks so much for your help.  The supplied code was excellent.  You Perl
>people are alright!  :-)
>
>In answer to Johnathan Kupferer's question at to my computing platform, I'm
>actually working on a Mac g4 running Mac OS X and am very interested in
>testing out its Perl programming capabilities.  If anyone has any
>suggestions for setting up that environment in Mac OS X, I'd be interested.
>
>Thanks,
>Curtis




Problem with reading string

2001-05-01 Thread jose

Hi,

I have a small problem, I'm trying to do the following.

I'm using WOTS to scan logfiles, and when it gets an error from our name server, it 
has to cut the error message in pieces separated by a space.
And has to compare it to the if statements. After that it has to copy a few pieces to 
make an email to warn our customers.
This is an example of an error message: 

Mar 16 12:12:04 ns4 named-xfer[16809]: [212.104.202.50] not authoritative for 
ero-art.com, SOA query got rcode 0, aa 0,
ancount 0, aucount 12

My problem is, when the script detects a ' [, ],(,)' It says  "no match" and it just 
stops.

My problem is the beginning of my script. I tried several ways to solve this, but to 
no avail.
The script is run in the following manner

namescript Mar 16 12:12:04 ns4 named-xfer[16809]: [212.104.202.50] not authoritative 
for ero-art.com, SOA query got rcode 0, aa 0,
ancount 0, aucount 12

the error is appended to my script, I can also do 

namescript "Mar 16 12:12:04 ns4 named-xfer[16809]: [212.104.202.50] not authoritative 
for ero-art.com, SOA query got rcode 0, aa 0,
ancount 0, aucount 12"

I hope you can help me with this, I've run out of options here. I'm used to C and not 
perl

Thanks in advance

Jose Vazquez
[EMAIL PROTECTED]

##
#!/usr/bin/perl

for ($i=0;$i<20;$i++) {
   @zin[$i] = $ARGV[$i];
   print "@zin[$i] \n\r";
}

#print "@zin";
#$_ = $zin;
# $zin = $ARGV;

print "$zin";

$ta = @zin[6];
$tb = @zin[7];
$tc = @zin[8];
$td = @zin[9];

for ($t=0;$t<20;$t++) {

if (@zin[$t] = /212.104.202.50/g) {
$name = "NS1.NETCASE.NL";
$email = '[EMAIL PROTECTED]';
$bericht ="Hoi wij krijgen de melding $ta $tb $tc $td van $name, kunnen jullie 
hier iets aan doen?";
}

elsif (@zin[$t] = /16809/g) {
$name = "NS1.test.NL";
$email = '[EMAIL PROTECTED]';
$bericht ="Hoi wij krijgen de melding $ta $tb $tc $td van $name, kunnen jullie 
hier iets aan doen?";
}

elsif (@zin[$t] = /212.104.194.5/g) {
$name = "NS.VSM-HOSTING.NL";
$email = '[EMAIL PROTECTED]';
$bericht ="Hoi wij krijgen de melding $ta $tb $tc $td van $name, kunnen jullie 
hier iets aan doen?";
}

elsif (@zin[$t] = /195.114.231.200/g) {
$name = "NS2.SUPPORT.NL";
$email = '[EMAIL PROTECTED]';
$bericht ="Hoi wij krijgen de melding $ta $tb $tc $td van $name, kunnen jullie 
hier iets aan doen?";
}

elsif (@zin[$t] = /212.104.201.196/g) {
$name = "NS1.SCHROER.NL";
$email = '[EMAIL PROTECTED]';
$bericht ="Hoi wij krijgen de melding $ta $tb $tc $td van $name, kunnen jullie 
hier iets aan doen?";
}

elsif (@zin[$t] = /212.104.197.10/g) {
$name = "NS1.PROMISUM.NL";
$email = '[EMAIL PROTECTED]';
$bericht ="Hoi wij krijgen de melding $ta $tb $tc $td van $name, kunnen jullie 
hier iets aan doen?";
}

else {
$email = '[EMAIL PROTECTED]';
open(M,"|/usr/sbin/sendmail $email") || die $!;
print M "Subject: Fout op nameserver!\n";
print M "\n"; # header en body scheiden dmv een lege regel
print M "@zin, $1, $&";
close M;
exit;
}

}
open(M,"|/usr/sbin/sendmail $email") || die $!;
print M "Subject: Er is een fout opgetreden bij ophalen domein van uw nameserver!\n";
print M "\n"; # header en body scheiden dmv een lege regel
print M "$bericht";
close M;
###





RE: Date stamping files

2001-05-01 Thread Grant McLean

You probably want to use Perl's built in 'localtime'
function rather than system("date").

Here's an example:

  my($day, $month, $year) = (localtime())[3,4,5];

  my $a = sprintf("%04u-%02u-%02u", $year + 1900, $month + 1, $day);

Here's a walkthrough ...

You can get the current time using time().  This function returns a
single integer being the number of seconds since January 1st 1970.
The number is also in GMT.

The localtime() function takes a time value and splits it into its
component parts (seconds, minutes, hours, day, month, year and more)
for your local time zone and returns these values as a list.  If you 
don't give localtime() a time value, it calls time().

In the sample code above, I only wanted the day, month and year so
I asked for elements 3, 4 and 5 of the returned list (skipping 
elements 0, 1 and 2).

There are two gotchas with the returned values (these are due to the
way the underlying operating system library functions work rather 
than Perl weirdisms).

The month numbers start at zero for January.  This is useful if you
want to use the number to index into an array of month names but if
you want a numeric value, you'll need to add 1.

The year number starts at 0 for 1900 so this year it's returned as
101.  To get a standard 4 digit year, add 1900.

I prefer my dates in the -MM-DD form when adding them in to
filenames - that way an alphabetical sort is also a chronological
sort.  I used the sprintf() function to add in the required leading 
zeros.

Regards
Grant

> -Original Message-
> From: Mark Martin [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, 1 May 2001 22:19
> To: [EMAIL PROTECTED]
> Subject: Date stamping files
> 
> 
> Does anybody know how to clean up the system time :
> 
> Tue May  1 10:18:32 BST 2001
> 
> or select only part of it to give a more managable date 
> format that can be
> used to stamp an output file from a program :
> 
> $a = system ("date");  # OR A TRUNCATED VERSION
> 
> # OR CLEAN IT UP HERE ???
> 
> $b = "filename.$a.txt"; # NOT SO SURE ABOUT THIS EITHER???
> 
> open (OUT2,">$b");
> 
> Thanks a lot!
> _
> 
> Mark Martin
> Computer Centre
> National University of Ireland Maynooth
> 
> Tel: (01)708 4716/3830
> Fax: (01)628 6249
> 



Re: Got a project for Perl but need some help

2001-05-01 Thread Curtis Michelson

Hey guys,

Thanks so much for your help.  The supplied code was excellent.  You Perl
people are alright!  :-)

In answer to Johnathan Kupferer's question at to my computing platform, I'm
actually working on a Mac g4 running Mac OS X and am very interested in
testing out its Perl programming capabilities.  If anyone has any
suggestions for setting up that environment in Mac OS X, I'd be interested.

Thanks,
Curtis





Date stamping files

2001-05-01 Thread Mark Martin

Does anybody know how to clean up the system time :

Tue May  1 10:18:32 BST 2001

or select only part of it to give a more managable date format that can be
used to stamp an output file from a program :

$a = system ("date");  # OR A TRUNCATED VERSION

# OR CLEAN IT UP HERE ???

$b = "filename.$a.txt"; # NOT SO SURE ABOUT THIS EITHER???

open (OUT2,">$b");

Thanks a lot!
_

Mark Martin
Computer Centre
National University of Ireland Maynooth

Tel: (01)708 4716/3830
Fax: (01)628 6249



RE: Removing an item from a list

2001-05-01 Thread King, Jason

David Kalnins writes ..

>I was wondering if it was possible to remove an item from a list whilst
>one is repeating over it with a foreach statement. For example, I was
>hoping that the following code fragment would do this - but instead it
>does exactly what I told it to do :) That is it leaves the item there
>but with an undefined value.

there's not really a way of doing it like you're doing because basically if
Perl removes the element then the next for iteration will skip the next
element

let me demonstrate .. one might be tempted to do this

  my @list = qw/alpha beta omega/;

  for( 0..$#list)
  {
splice @list, $_, 1 if $list[$_] =~ /b/;
  }

and for the current example that will work .. but try it for this list

  qw/alpha beta bingo omega/;

and you'll see the problem .. the splice chops out that element - and the
next element slots down to take its place .. then the for loop goes to the
next element and tests it and misses the one that slotted down

also .. the end of the array is reached before the loop is finished (because
the array has shrunk) so when run under warnings - the above code generates
warnings

so what to do .. well instead of deleting items from the current list we
really need to create a new list which contains everything other than what
we don't want

wouldn't it be nice if Perl had some sort of function which iterated over a
list testing each element as it went and returned the resulting list

well .. I'm glad you asked .. enter the 'grep' function .. your code turns
into this

  my @list = qw/alpha beta bingo omega/;

  @list = grep { ! /b/ } @list;

  print join( "\n", @list);

and as you can see .. like all other assignments - we're able to use the
same container for the result that we're using for the input

and also - when outputting a list with a common separator between the
elements .. give 'join' a go in your print statement .. much neater than
another for statement

  perldoc -f grep
  perldoc -f join

-- 
  jason king

  A Canadian law states that citizens may not publicly remove bandages.
  - http://dumblaws.com/



RE: Hash of Arrays Question

2001-05-01 Thread King, Jason

J. Patrick Lanigan writes ..


>I haven't quite sorted out the more complex data structure in perl yet.
>Anyhow, I need to take the following hash of arrays...


you have some very confusing code there .. so let's do it one bit at a time


>my %tracks = ();

create a hash called tracks with zero elements


>push @{$tracks{$filename}},
>   $_, # tracks.filename

>   $File::Find::dir . '/', # tracks.filepath
>   $artist,# artist.artist_name
>   $album, # album.title
>   $tracknum,  # tracks.track_num
>   $title, # tracks.title
>   $genre; # tracks.title

create a new element of the tracks hash using the value of the variable
$filename as the key

treat that new element as an array reference and push a bunch of values onto
it

assume for a secont that $filename has the value 'file1' .. at this point in
the code you have something like the following structure

  %tracks = ( file1 => [ $_, 'some/path/', 'artist_name', 'etc...' ] );

I didn't continue it .. but as well as the artist name you've got the album
title, the track number, title, and genre in there .. you get the drift

but you've got only one member of the %tracks hash .. it's key is the value
of $filename and it's value is an array reference as above


>for my $row ( keys %tracks ){

so now we grab the keys of %tracks - of which there is only one - 'file1' in
our example .. then we stick that into $row

>   (my $qualified_filename, my $filename, my $filepath, 
>$artist, $album, $tracknum, $title, $genre) = 
>"$row @{ $tracks{$row} }";

now we create a string containing the key ('file1') then a space and then
the values of the array referred to by $tracks{file1}

it's a single value - so it goes into the first element of the lvalue list -
ie. $qualified_filename

the following code would have done EXACTLY the same as what you've done
above

  my %tracks;

  $tracks{$filename} = [ $_,
 $File::Find::dir . '/',
 $artist,
 $album,
 $tracknum,
 $title,
 $genre,
   ];

  my $qualified_name = "$filename @{ $tracks{$filename} }";

so .. as you can tell - you'll have to explain a bit more about what you're
trying to do .. because it's really not clear

-- 
  jason king

  A Canadian law states that citizens may not publicly remove bandages.
  - http://dumblaws.com/



Removing an item from a list

2001-05-01 Thread David_Kalnins

Hi all,

I was wondering if it was possible to remove an item from a list whilst one
is repeating over it with a foreach statement. For example, I was hoping
that the following code fragment would do this - but instead it does
exactly what I told it to do :) That is it leaves the item there but with
an undefined value.

my @list = qw ( alpha beta omega );

foreach (@list)
{
/b/ && undef($_);
}

foreach (@list)
{
print "$_\n";
}

Any thoughts?

Thanks in advance.

David Kalnins





Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan

I haven't quite sorted out the more complex data structure in perl yet.
Anyhow, I need to take the following hash of arrays...

my %tracks = ();

push @{$tracks{$filename}},
$_, # tracks.filename  
 $File::Find::dir . '/', #
tracks.filepath
$artist,# artist.artist_name
$album, # album.title
$tracknum,  # tracks.track_num
$title, # tracks.title
$genre; # tracks.title

...and then extract the data...(This isn't working)

for my $row ( keys %tracks ){
(my $qualified_filename, my $filename, my $filepath, $artist, $album,
$tracknum, $title, $genre) = "$row @{ $tracks{$row} }";
{   

...what I end up with, is ALL my data in $qualified_filename.

Solutions? 
Thanks,
Patrick




RE: flock for win32

2001-05-01 Thread King, Jason

RDWest writes ..

>i just joined the list. i've been fooling with perl scripts for a
>few months now. just installing and editing html output mainly... now
>i'm studying a coupkle books to write my own (i hope)
>
>question: i've seen a couple post in some forums about creating a temp
>file for a lock on win32(i know win32 doesn't support FLOCK)
>
>these post had a couple of contradictions about them...
>
>does anyone know a stable way to lock a file on win32?

the term "Win32" that you use isn't specific enough .. flock is buggy on
Win9x .. but works perfectly on WinNT

  use Fcntl ':flock';
  open FILE, 'file' or die "Bad open: $!";
  flock FILE, LOCK_EX;

if you're on Win9x and need to lock a file then you don't really have an
option other than to get a real operating system (sorry ;)

as for creating a temporary file .. usually there's no locking involved -
because you'll usually use a different filename for each temporary file that
you create

your best bet is to check out the perl FAQ which was installed on your
system when you installed Perl

you can get to by typing the following at a command prompt

  perldoc -q temporary

there are a few different solutions for different situations

there are also a number of FAQ items on file locking - if that's actually
what you need

  perldoc -f lock

-- 
  jason king

  A Canadian law states that citizens may not publicly remove bandages.
  - http://dumblaws.com/