Re: HTML page seperator or page breaks?
On Mon, 18 Feb 2002 at 16:44 GMT, Carolyn Bentley wrote: I need to be able to create a web page that has page breaks in it. snip I think there might be a way to do this with tables. However I cannot find any documentation about it. Is there anything you might suggest trying? Although this is more a HTML/CSS question, you may want to look at the following CSS2 properties: page page-break-before page-break-inside page-break-after (although they are not supported by every browsers - Opera5/6 and IE5.5/6, and maybe Mozilla) Documentation and examples can be found in the CSS2 specifications: http://www.w3.org/TR/CSS2/page.html -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: removing white space revisited
On Mon, 18 Feb 2002 at 18:48 GMT, David Gilden wrote: Hi, My goal is to clean up the fields submitted from a form and then be able to use them in other places. Do I have to assign my 'cleaned' data to a hash? You can try it by yourself: #!/usr/bin/perl -w use strict; use CGI qw(:cgi); foreach my $key ( param() ) { my $value = param($key);# Fetch the parameter value $value =~ s/^\s*|\d*\s*$//g;# Strip whitespaces and trailing digits param( $key, $value ); # Reassigning the value in the parameter } # We verify the parameters to see if the values were changed foreach ( param() ) { print $_ = ', param($_), '\n; } __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl Regular Expressions
On Mon, 18 Feb 2002 at 22:44 GMT, Karl Kittler wrote: I'm also trying to figure out how to collect both the URL and the link name in one line of code. From what I've read, it looks like it can be done. Forget regexes, use a proper HTML parser. TokeParser is nice for this task #!/usr/bin/perl -w use strict; use HTML::TokeParser; my $p = HTML::TokeParser-new(\*DATA) or die Cannot read DATA: $!; my %links; while ( my $token = $p-get_tag('a') ){ my $url = $token-[1]{href}; my $text = $p-get_trimmed_text(/a); $links{$url} = $text; } while ( my ($url, $text) = each %links ){ print $url = $text\n; } __DATA__ html headtitleTest TokeParser/title /head body a href=hello.htmlHello World!/a pSome text a href=goodbye.htmlGoodbye cruel world/a /p a style=font-size:18pt href='foo.html'Foo!/ap /body /html __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing to a file
On Sat, 16 Feb 2002 at 01:19 GMT, Naika - Ev1 wrote: I'm trying to write to a file from a 5 choice radio form and I keep getting this error Undefined subroutine main::param called at pollresults_rg.pl line 5. What does that mean? It means that the param() subroutine can't be found in the main package (your program). But in fact, you really want to use the CGI.pm param() subroutine (CGI::param). To be able to use it directly in your program, you must first import it with a statement like 'use CGI qw(param);' at the top of your script. -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: References/unitialized variable error message
On Sun, 17 Feb 2002 at 00:07 GMT, Geoffrey F. Green wrote: Hi. Newbie to perl here. I've got two problems (well, two perl-related problems), relating to the same program. To iterate over a hash, you want to use the keys() function. foreach my $keys ( keys %table) { print $table{$keys}-{search},\n; print $table{$keys}-{shortname},\n; } Otherwise, perl iterates alternatively over the keys and the values of the hash, which causes the extra newlines and the warnings. -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Percent printing in CGI...
On Thu, 14 Feb 2002 at 19:46 GMT, Jerry Everett Jr wrote: I am having a problem printing percents within my PERL program when I add in CGI. You have a problem with your parens in the printf function. #!/usr/bin/perl -w use strict; use CGI qw(:html); for my $percent ( 0.5, 5.434, 12.12, 100 ){ printf(p('2.Percent addresses used: %2.0f%%'), $percent) } __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help ...
On Fri, 15 Feb 2002 at 00:42 GMT, Jason Lamar wrote: I purchased a Mail This Page To A Friend script that I'm doing some tweaking on, but I can't figure out a particular item in the function that parses HTML code to be formatted into a standard e-mail message. snip ... so that only the Image Description is left. Basically, I want to delete all the rest of the code but leave the alt tag information intact. use a proper HTML parsing tool to do that for you. HTML::Parser is quite easy to use with little practice. #!/usr/bin/perl -w use strict; use HTML::Parser 3; my $html = '_HTML_'; pHello img src=/gifs/earth.gif with=30 height=30 alt=World /!/p _HTML_ HTML::Parser-new( report_tags = ['img'], start_h = [ sub { print shift-{alt} }, 'attr' ], text_h = [ sub { print shift }, 'dtext' ], )-parse($html); __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: redirect script failling
On Wed, 13 Feb 2002 at 23:48 GMT, David Gilden wrote: Can someone point why the following is not working? According to the CGI.pm doc (perldoc CGI): The redirect() function redirects the browser to a different URL. If you use redirection like this, you should not print out a header as well. -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: array question
On Wed, 13 Feb 2002 at 02:29 GMT, Pankaj Warade wrote: This is work my @array = ( 1, 2, 3, 4 ); print $#array; --- size of array. Actually, $#array holds the indices of the last element, not the size of the array. @array in scalar context returns the number of elements in the array #!/usr/bin/perl -w use strict; my @array = qw(1 2 3 4); print Number of elements: , scalar @array, \n; print Last element: , $#array, \n; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl parameter in html-tag
On Tue, 12 Feb 2002 22:54:36 +0100 (MET), Terje Bremnes [EMAIL PROTECTED] wrote: Any ideas here? Do I need to split the $word into an array (vector) in order to separate URL-links? That's the idea, though the backtick operator can be used in list context, like this: #!/usr/bin/perl -Tw use strict; @ENV{qw(PATH BASH_ENV)} = ('',''); my $value = $ARGV[0]; $value =~ m/^(\w+)/; # untaint $value = $1; chomp(my @results = `/bin/grep -inlsh $value perl/*`); print pThe string '$value' was found in these files:/pul\n; foreach (@results){ print qq'lia href=$_$_/a/li\n'; } print /ul; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how do I make a input from STDIN to be silent??
On Tue, 12 Feb 2002 12:15:17 +1100, Ivan Teliatnikov [EMAIL PROTECTED] wrote: I want to read a passwd string from the terminal but without displaying it back to the screen. perldoc -q password #!/usr/bin/perl -w use strict; use Term::ReadKey; print Password: ; ReadMode('noecho'); chomp( my $password = ReadLine(0) ); ReadMode('normal'); print \nYou entered '$password'\n; __END__ Thank you. -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Use of Spllic command
On Tue, 12 Feb 2002 14:46:45 -0800 (PST), Kevin Butters [EMAIL PROTECTED] wrote: I have an array with 5 elements, 0-4. I want to insert values into the array at position 2. Do I use the splice command? splice(@array, 1, value); print @array\n; 0 1 2 3 4 5 You forgot the length argument to the splice function #!/usr/bin/perl -w use strict; my @array = (0..4); print @array\n; splice(@array, 1, 1, value); print @array\n; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Time conversion question
On Tue, 12 Feb 2002 17:03:00 -0600, Shawn [EMAIL PROTECTED] wrote: How might I convert a date/time string to epoch seconds? For example, taking 02/05/2002 02:31:14 and convert to epoch seconds. One easy way to do it is to use the standard Time::Local module: #!/usr/bin/perl -w use strict; use Time::Local; my $time_string = 02/05/2002 02:31:14; my ($mday,$mon,$year,$hours,$min,$sec) = split(m![/ :]!, $time_string); my $time = timelocal($sec,$min,$hours,$mday,--$mon,$year); print Epoch: $time\n; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ELO/HELO
On Sat, 9 Feb 2002 19:23:23 -0800, Octavian Rasnita [EMAIL PROTECTED] wrote: Hi all, Do you have any idea what is ELO and what is HELO? I sent a message and I saw in the headers from unknown (HELO). Thank you for some light. I'm assuming from your last e-mail on the list that you're speaking of the HELO command in the SMTP protocol. This command is used to identify yourself to the SMTP server at the beginning of the transaction (though you can use it later on too IIRC) It has the form: HELO your.host.name The server usually do a reverse lookup to see if the name you gave is correct. It should reply with a line greeting you, like: 250 smtp.server.com Hello your.host.name(or whatever hostname it found during the reverse lookup) obPerlContent: with Net::SMTP the hostname you give during the HELO command can be set in the constructor with the Hello = 'hostname' parameter -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: The SMTP protocol
On Sat, 9 Feb 2002 09:54:31 -0800, Octavian Rasnita [EMAIL PROTECTED] wrote: Do you know where I can get information about the SMTP protocol? I read in a module that it is explained in RFC821. Where can I found this RFC? http://www.google.com/search?q=RFC821 with a bit of luck, you'll find it right away Will I understand the SMTP protocol from there, to be able to make a script for sending mail? If you like to spend your weekends reading RFCs, this one will probably tell you how the SMTP protocol works. But if you're impatient and/or lazy and want to send mail right away, you can use one of numerous CPAN modules that handles SMTP protocol like Net::SMTP, Mail::Sender, Mail::Sendmail, Mime::Lite, etc. -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Keys and values
On Sat, 09 Feb 2002 13:49:59 +, Terri Harrison [EMAIL PROTECTED] wrote: What do I do so that the Name is the key and the Species and Gender together are the value? You were not too far from what you wanted to do. #!/usr/bin/perl -w use strict; my %zoo; while (DATA){ chomp; # Split the line in two elements, after the first space my @elements = split(/ /, $_, 2); # Assign the first element as the key and the last as the value $zoo{$elements[0]} = $elements[1]; } # Let's check the results: print $_ = $zoo{$_}\n foreach keys %zoo; __DATA__ Happy Cat Male Evil Snake Female Patches Dog Male Bubbles Fish Female Harley dog Female Goldy Fish Male __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Renaming files with Perl
On Fri, 8 Feb 2002 06:48:56 -0800, Troy May [EMAIL PROTECTED] wrote: Hello, I posted a question about this a couple days ago and only got 2 responses, but neither of them worked for him. So I figured I'd start new since he told me the EXACT format he would like the files to be in. My friend wants to rename a dat file as he calls it. (message.dat?) He would like to rename them in this exact format: the word mess, current date (2 character format) then the extension .html. So if he would run this today, the renamed file would be: mess020802.html Any ideas on this? He's really bugging me about it. :) #!/usr/bin/perl -w use strict; my $file = 'message.dat'; my ($d,$m,$y)=(localtime)[3,4,5]; my $newname = sprintf('mess%02i%02i%02i.html', $d, ++$m, ($y+1900)%100); print $file = $newname\n; rename($file, $newname) or warn Could not rename '$file' to '$newname': $!\n; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Mucking around with txt and arrays
On Fri, 01 Feb 2002 18:52:18 -0500, Steven Rubin [EMAIL PROTECTED] wrote: Create a script that formats a txt file into html. Well, that's kinda vague. I mean... If the text files looks like the one you have below, with entries separated by blank lines, here's a rough outline of what you could do: Hope this helps, Briac #!/usr/bin/perl -Tw use strict; use CGI qw(:standard); my @entries; { local $/ = ''; # Paragraph reading mode while (DATA){ chomp; my @datas = split(/\n/, $_); push( @entries, [@datas] ); } } use Data::Dumper; print Dumper @entries; print header(), start_html('CGI people'), table( map { Tr(td([@$_])) } @entries ), end_html(); __DATA__ Steven http://blah.com Web design and basketball USA Bill http://bill.org Butterfly chasing and Database administration USA __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: width of table cells and CGI ???
On Thu, 31 Jan 2002 13:58:04 +0100 (CET), Martin A. Hansen wrote: thats is pure HTML code... i know! i want to do it the CGI way! aint there a -width = 150 switch i can set? ... td({ width = 150 }, ['Title', $title]), ... -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html entity conversion... one liner?
On Thu, 31 Jan 2002 14:06:06 -, Michael Kavanagh [EMAIL PROTECTED] wrote: I thought it would be good to be able to do this: $item = blah; $item =~ tr//(lt;)(gt;)/; to convert those symbols to their entity references. however, the tr operator doesn't seem to like using () to group... any comments on how to make this operation in to a one-liner? Here's a possible suboptimal one-liner approach: #!/usr/bin/perl -w use strict; my $item = gahbuh/gah zoh; $item =~ s/([])/''. ($1 eq'' ? 'l':'g') . 't;'/eg; print $item; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading text
On Tue, 29 Jan 2002 21:56:38 -0600, Michael Pratt wrote: What is the simplest means of reading a text file line by line. #!/usr/bin/perl -w use strict; open(FILE, ' file.txt') or die Cannot open file: $!\n; while(FILE){ # Read each line of file.txt until end of file. # the current line content is in $_ print Current line: $_; } __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getopt::Long problem (Allegedly)
On Wed, 30 Jan 2002 21:47:15 -, Angus Laycock wrote: --=_NextPart_000_01D4_01C1A9D7.AEC826A0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi, I wrote this today on UNIX . When I tested the script, calling it with all the options (f s D P U S e q ) the -s option would not return the value from the command line. All the other variables got populated. I then change the s:s to f:s and that worked. I am trying to replace some software which uses -s as an option and need to handle the options the same in the PERL replacement. Is there a bug with s:s? By default, Getopt::Long is case insensitive. Try adding the bundling and ignore_case options. cf perldoc Getopt::Long (Configuring Getopt::Long) #!/usr/bin/perl -w use strict; use Getopt::Long qw(GetOptions); Getopt::Long::Configure (bundling, ignore_case); my($DATABASE, $PASSWORD, $USER, $SERVER, $ERR, $SPROC, $QUERY, $TT) =('')x8; GetOptions( 'f:s' = \$TT, 's:s' = \$SPROC, 'D:s' = \$DATABASE, 'P:s' = \$PASSWORD, 'U:s' = \$USER, 'S:s' = \$SERVER, 'e' = \$ERR, 'q:s' = \$QUERY ) || die Options incorrect\n; print _EOT_; DATABASE = $DATABASE PASSWORD = $PASSWORD USER = $USER SERVER = $SERVER ERR = $ERR SPROC= $SPROC QUERY= $QUERY TT = $TT _EOT_ __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: parsing multi-line records
On Mon, 28 Jan 2002 15:02:31 -0800, David Palomino wrote: I am trying to parse lpstat -s output from HPUX. There are two lines per record. It looks like this: Playing with the $/ might help you a bit here #!/usr/bin/perl -w use strict; $/ = 'device for'; my $header = DATA; while (DATA){ my ($dev1,$remote,$on) = / ([^:]+):.*?to: (.*) on (\w+)/s; print $dev1,$remote,$on\n; } __DATA__ no system default destination device for ms331x_lzr: /dev/null remote to: ms331x-lzr on spooler1 device for df447x_lzr: /dev/null remote to: df447x-lzr on spooler2 device for cvacct4_lzr: /dev/null remote to: cvacct4-lzr on spooler3 device for myprinter: /dev/null remote to: cvacct5-lzr on spooler3 __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Form-Click questions
Guy Davis wrote: I apologize if this is making no sense. Since I am using someone else's code I still have a lot of fuzziness about what is actually happening. A little nudge in the right direction would be helpful and greatly appreciated. Maybe you would find the webchatpp application (provided with in the webchat distribution: http://search.cpan.org/search?dist=webchat) This application creates the whole code for requesting pages, submitting forms, fetching other pages according to the results of the submission, etc. Here's a quick example ---% chatscript # Initialize some perl stuff $ua ||= new LWP::UserAgent; my $agent = shift || 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)'; ## Set some User Agent properties. $ua-agent($agent); $ua-timeout(30); # 1) I pass a URL, username, password GET https://secure.overture.com/s/dtc/center/ EXPECT OK # 2) The URL is opened and scanned for a login form FORM login # 3) The form once found is populated with the passed username and #password F UserName=username F /go2/directraffic/handler/LoginFormHandler.password=s33kr3t # 4) form-click is called which makes the $click-is_redirect() routine #equal to true at this point SUBMIT login EXPECT OK # 5) open the redirected page as in #2 above and do some more form and #submit stuff (this is where I'm having problems... I don't know how #to 'open' this redirected page) # The content redirected form is stored in $_ FORM another_form F foo=bar SUBMIT EXPECT ERROR __END__ - chatscript ---%--- Then, you can type: $ webchatpp chatscript | perl And hopefully it will do what you want... -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using system variables (M$ OS's)
Andrew Mason wrote: I would like to print a line containing the value of a system variable (I'm running on M$ NT4). #!/usr/bin/perl -w use strict; print Blah blah $ENV{IPADDRESS} blah!\n; __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: binmode with graphics, @ARGV, -T switch
In article a05101204b8710279a226@[24.70.235.44], Harvey Quamen wrote: 1) This script doesn't really translate from a jpeg to a PNG, does it? The $image_type is simply for the header, right? I got confused because the book says, So we will provide a high-color, high-detail PNG if possible, or a JPEG otherwise but it seems like the script is just dumping the data untouched right to STDOUT. No, there's no file format conversion done by this script. It just check if the user's browser can accept PNG files (or, in my example, prefers them over JPEG files.) According to this user preference, the script displays the image in the right format (but a version of the same image must be provided in the two formats.) 2) More description: If a user calls this with http://localhost/cgi/image_fetch.cgi/new_screenshot.png, he or she will actually get new_screenshot.png or new_screenshot.jpeg depending on what the browser supports. I can see that the script is pulling the filename from $ENV{PATH_INFO} but could this data also be retrieved from @ARGV? I tried a version with @ARGV, but it didn't seem to work, and I wasn't sure if it was due to @ARGV or me. No, the @ARGV array is useless in this case since there are no arguments passed to the script. Two ways of fetching informations from outside the script are the CGI parameters (either with POST or GET method), and the http server environement variables, which can be found in the hash %ENV. The modified version below uses CGI.pm to avoid the hassle of remembering all the environements variables set by the http server. The added benefit of using CGI is that it provides a path_translated function that translates the additional path info (in our case, the filename) into the full path in the file system. (By the way, it would be smart to use File::Basename for this type of thing, wouldn't it? We could, but perl is generaly smart enough to translate '/' to '\' on Windows, for example. And the path_translated function should probably give back what you are expecting too. And is that why there are extra parentheses around the my $basename declaration? It's not in a list context, is it?) Yes it is! the m// operator returns true or false (1/0) if it matches, which is handy in for example: print matched if m/Foobar/; If you look at the documentation (perldoc perlop), you'll read somewhere that the m// operator: Searches a string for a pattern match, and in scalar context returns true if it succeeds, false if it fails. [...] m// in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., ($1, $2, $3...). So you can see that the (\w+), if it is matched, is returned in in the $image_path variable. Not that if we wanted to keep track of the file extension the user gave, we could have said for example: my ($image_path, $image_ext) = path_translated() =~ /(\w+)\.([^.]+)$/; 3) The Camel and the Pocket Reference both say that binmode needs a filehandle. I'm guessing the Perl in the Guelich et al book is a slightly older version? So I should expect a few more of these syntax differences as I go through the book? (I actually never got this version of the script to run, even with setting up some directories and files, but managed very well with the one in the Camel, p. 686.) I don't have the book right here, but in doubt, check the perldoc with up to date information on function use. For example, to get the doc about binmode(): $ perldoc -f binmode 4) When I test for syntax errors on the command line, I get the following: Too late for -T option at image_fetch.cgi line 1. I'm using Perl 5.6.0 and Apache 1.3.20 on Mac OS 10.1. Try adding the -T switch on your command line: $ perl -T myscript.pl #!/usr/bin/perl -wT # Same script, using CGI.pm (untested though) use strict; use CGI qw(:standard); my $image_type = Accept('image/png') = Accept('image/jpeg') ? 'png' : 'jpeg'; my ($basename) = path_translated() =~ /^(\w+)/; my $image_path = $basename.$image_type; unless ( $basename and -B $image_path and open IMAGE, $image_path ) { redirect('http://mysite.com/errors/not_found.html'); exit; } my $buffer; print header( -type = image/$image_type, ); binmode STDIN; while ( read( IMAGE, $buffer, 16_384 ) ) { print $buffer; } __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DBD_ACCESS
=?Gb2312?Q?Yun=20yun?= wrote: I want to do a small test on database in perl using MS Access database, but I find there is no DBD_ACCESS in the DBI.pm, should I download it from somewhere? the same thing with the database DB2 and other database. Thanks! To use DBI with MS Access databases, you must use DBD::ODBC. You can also use Win32::ODBC if you want to access(!) Access-specific meta datas. http://search.cpan.org/search?dist=DBD-ODBC http://search.cpan.org/doc/GSAR/libwin32-0.18/ODBC/ODBC.pm -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to make it more perlish
In article [EMAIL PROTECTED], Frank wrote: On Fri, Jan 18, 2002 at 11:39:11AM +0100, Jorge wrote: my @PROG=( c:\\OXE\\cygwin\\bootp\\linux\\$_Globals{LX_VERSION}, 'c:\\OXE\\cygwin\\bootp\\linux\\install', 'etc...'); If you want to be a little more perlish, you can avoid the '\\' and put '/' instead, perl will do what you mean, and it's good for your laziness, too. -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regex Assistance
In article 2FB59B145095D511A7C90050BAC349F31730A3@MAIL, John Edwards wrote: I need a routine that will look at the filename, if that filename already exists, then add a (1) to the end. I've got the checking for existance sorted, it's the generation of the new file name that is the issue. Here's a possible way to do it: #!/usr/bin/perl -w use strict; myRename('Sherlock(1).all'); sub myRename { my $filename = shift; warn Can't find '$filename'\n and return unless -e $filename; my $newname; if ( $filename =~ m! (.*) \( (\d+) \) \. ([^.]+) $!x ){ - --- _ | | || | filename number in () dot extension eol $newname = $1( . ($2+1) . ).$3; } else { ($newname = $filename) =~ s/\.([^.]+)$/(1).$1/; } rename ( $filename, $newname ) or warn Could not rename '$filename' to '$newname'\n and next; print $filename = $newname\n; } __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Thumbnail images on-the-fly
Scott R. Godin wrote: snip any pointers? I'm happy to toddle off and download and read my face off -- that's not a problem.. I'd just like to have some indication on which direction to start walking. :-) Here are some Pictures Gallery-type modules that can be found on CPAN: Apache::Album: http://search.cpan.org/search?dist=Apache-Album HTML::PhotoAlbum: http://search.cpan.org/search?dist=HTML-PhotoAlbum Apache::PhotoIndex: http://search.cpan.org/search?dist=PhotoIndex As for image manipulation tools, I use Image::Magick, which is really powerful. The only drawback is that the learning curve is quite steep as the documentation for this module can be hard to follow. http://www.imagemagick.org/ http://search.cpan.org/search?dist=PerlMagick http://magick.net4tv.com/MagickStudio/scripts/advanced.cgi Good luck with your project! Briac -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: subroutine returning lines of text
Martin A. Hansen wrote: im wondering how i can make a subroutine that will return all text lines between certain marks such as START and STOP: Here's simple way to do it. It uses the '..' operator (see perldoc perlop for more info about it). Note that if START and STOP are in the same line, it will only print this line. If you want to force START and STOP to be on different lines, try using the '...' operator. #!/usr/bin/perl -w use strict; my $start = 'START'; my $stop = 'STOP'; while (DATA){ print if /$start/ .. /$stop/; } __DATA__ text is here and there START text is here and there is a lot of it STOP text is here and there __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Win32::ActAcc - where from to download
Abhra Debroy wrote: Can anybody tell me where from I can down load 'Win32::ActAcc'. I tried it from CPAN but failed. Get the .zip here: http://cpan.valueclick.com/authors/id/P/PB/PBWOLF/Win32-ActAcc-0.5.zip then: 1 Unzip the zip (Win32-ActAcc-n.n.zip). Make sure your unzip program preserved the directory tree: for example, you should see Win32-ActAcc.tar.gz in an x86 subdirectory under the directory that contains ActAcc.html (the documentation). 2 Open a command prompt window. 3 In the command prompt, cd to the directory that contains ActAcc.html. 4 In the command prompt, issue the following command: ppm install --location=. Win32-ActAcc -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Running commands as variables
In article [EMAIL PROTECTED], David Ulevitch wrote: I am trying to do this: $ns1_in = `/usr/local/sbin/iptables -xvnL |grep 'mrtg' |grep -v 'Chain' |grep 'ns1-in' |awk '{print $2}'`; but perl thinks the $2 is for it so it evals it (to '') and then awk in return prints the whole line, as opposed to the $2 that I want. try with the following syntax: $ns1_n = qx( ... ); the qx() operator acts as the q or qq operator, by allowing you to choose your own set of delimiters. see perldoc perlop for more infos. -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tables in CGI
In article 02011510194302.01235@gandalf, Gerry Jones wrote: To recap: I don't need help with DBI or querying DB's, but with printing the results into a table. I have two arrays: @columns (contains the column names from the queried table), and @data (contains every row from that table). I tried to adapt the code in Lincoln Stein's book, but all I got was a table with the column headings and the first row was filled with the @data array. Here's how I would probably do it using 'pure' CGI.pm. I assume that @data is an array of arrays, each sub-array being a row. #!/usr/bin/perl -w use strict; use CGI qw(:html); my @columns = qw( FooBar Baz Quux ); my @datas =([qw( Eenie Meenie )], [qw( Barney FredWilma)], [qw( Just Another Perl Hacker )], ); print start_html('CGI Table'), table( { -border = 1 }, Tr( [ th(\@columns), map {td($_)} @datas, ]) ), end_html(); __END__ -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: tables in cgi for briac pilpre'
Nafiseh Saberi wrote (in perl.beginners): hi. hope you be fine. i reply this question,also. (tables in cgi) do you know what is the difference between my answer and yours,or what is the advantages ?? Your answer is probably faster than mine in execution time since you don't have to call CGI methods to print a HTML table. However, using CGI.pm to create HTML, is in my opinion, a safeguard against HTML inconstencies. I think also makes the code more readable, as it is 100% perl and not a mix between perl and HTML. And an added bonus is that CGI.pm outputs by default (generally) valid XHTML. Of course, if you want to make really complex things in HTML, CGI.pm can be limitating. But in these case, I'll probably use a proper Templating tool (like HTML::Template, or better, Template Toolkit or HTML::Mason, all available on CPAN) I hope all of this makes sense! I think..your mail have problem and returned. Yes, my mail is 'spam armored', you have to remove the capital words 'NO' and 'SPAM' from my address. Briac -- briac dynamic .sig on strike, we apologize for the inconvenience -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regex improvment needed
Jorge Goncalvez wrote: Hi, I have this code to parse a file and get the hardware address: snip It works fine but if that comes after hardware ethernet contains a..f in lowercase the letter are ommitted. How can i get rid of this behaviour. #!/usr/bin/perl -w use strict; use vars qw(%_Globals); ParseInitDhcpdconf(); print $_ = $_Globals{$_}\n for keys %_Globals; sub ParseInitDhcpdconf { while (DATA) { if (/{hardware ethernet\s+([:0-9a-z]+);/i) { print found $1\n; $_Globals{MAC_ADDRESS} = uc($1); } } } __DATA__ host clin09 {hardware ethernet 00:56:9C:6B:8A:15; ... but it can be for exemple ... host clin09 {hardware ethernet 00:56:9c:6b:8a:15; . -- briac Seven trout out of the pool. A flying thrush. A fox walks. A songbird. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using print
Evan Panagiotopoulos wrote: I have a text file and I would like to use the print command. I read the documentation but I couldn't make heads or tails. I have the variable containing the string in variable $fields{add}, the text file in in variable taxfile.dat, and the receiving variable is $lines. Okay you want to print every lines of a file (taxgfile.dat) that match the string in $field{add} ? Here's a way to do it: #!/usr/bin/perl -w use strict; my %fields = ( # We use quotemeta to avoid interpreting special characters # (like *, +, ?) in the regular expression 'add' = quotemeta('string to match'), ); open(FILE, taxfile.dat) or die Cannot open taxfile.dat: $!\n; while (FILE){ print if /$fields{add}/i } __END__ Hope this helps, Briac $lines = print if (/(?i) $fields{add}/ ) taxfile.dat; I wanted to ignore the case (upper or lower is irrelevant). HELP, after many hours of trying, searching and cursing I finally give up and I ask for your suggestions. Thanks, Evan Panagiotopoulos -- briac A pair of lovers contending under an oak. A old man. A bear walks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Dependencies script
In article [EMAIL PROTECTED], Gary Hawkins wrote: In private correspondence, the esteemed bcc'd entity penned: hi again. i work with perl, but I dont know,for what purpose you want to do that ? for which puepose? Or you can install the Devel::Modlist module, and just type: perl -d:Modlist myscript.pl And have all the use'd and require'd modules and files needed by the script printed. http://search.cpan.org/search?dist=Devel-Modlist -- briac A rabbit sniffs near a farmer's cottage. Four quacking ducks. A duck quacks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: extracting links from HTML data
In article [EMAIL PROTECTED], Lorne Easton wrote: I need to write some code that extracts that extracts hyperlinks from a scalar ($data) and puts them into an array. I imagine that grep can do this, but my mastery of it and reqular expressions are not brilliant. Can you please provide some example code, or at least point me in the right direction? If you only need the URLs of the hyperlinks, then HTML::LinkExtor is just what you need, and it is provided with HTML::Parser. HTML::SimpleLinkExtor might be worth a try too. http://search.cpan.org/search?dist=HTML-SimpleLinkExtor http://search.cpan.org/search?dist=HTML-Parser Otherwise, if you want the URLs and the text inside, something like the following might work: #!/usr/bin/perl -w use strict; use HTML::Parser 3; my $data = '_HTML_'; pa href=http://foo;bar/abr foo text baz a href=http://baz;quux/a/p _HTML_ my @links = parse_links($data); # We now print the links we found my $count; foreach (@links){ print ++$count . . Description: $_-[1]\n URL: $_-[0]\n\n } sub parse_links { my $data = shift; my ( @links, $inside ); my $count = 0; # Preparing the parser my $linkparser = HTML::Parser-new( report_tags = ['a'], # Only dealing with A tags unbroken_text = 1, # Avoid text split over several lines # Called each time a A ... is found start_h = [ sub { # Storing the HREF attribute $links[$count] = shift-{href}; # We should recall we're inside a A element $inside = 1; }, 'attr' ], # Called when /A is found end_h = [ sub { $count++; $inside = 0; }, '' ], # Called when text is found text_h = [ sub { # We're only interested in text inside a.../a return unless $inside; # Store the text with the previous stored HREF # attribute $links[$count] = [ $links[$count], shift ]; }, 'dtext' ], ); # Launch the parser $linkparser-parse($data)-eof(); return wantarray ? @links : \@links; } __END__ -- briac A flying swallow. A fox stalks under a she-oak. A nesting dove. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Multiple Substitutions with RE on a single line?
Tim Sargent wrote: snip I'd prefer an efficient and neat method to do all this, but am rather stuck. Any pointers that can get me started down the right path would be greatly appreciated...I know there's an answer out there, I'm just having a devil of a time finding it. Sorry for the lengthy post. I would store all the possible transformations in an array, containing the regex and the replacement string. the iterate over the array and replacing each occurences as they are found: As for avoiding repeating replacement, I just tweaked the 'green' regex a little bit by adding a (?!\.p) at the end ( look-ahead negative assertion: the string '.p' must not be found after /GS\d/ ) #!/usr/bin/perl -w use strict; use 5.6.0; my @transfo = ( [ qr/\b(GS\d{1,2}\.p\d+-\d+\b)/, 'green-atu' ], [ qr/\b(GS\d{1,2})(?!\.p)\b/,'green' ], [ qr/\b(launch)\b/i, 'launch'], [ qr/\b([BS]\d{1,2})\b/, 'blue' ], ); my $text = '_TEXT_'; GS5 launches 3 plasma torpedoes (GS5.p1-3), warhead strength 20, speed 32 _TEXT_ foreach my $case (@transfo){ $text =~ s{$case-[0](?!span)} {span class=$case-[1]$1/span}ig; } print Result:\n$text; __END__ Result: span class=greenGS5/span launches 3 plasma torpedoes (span class=green-atuGS5.p1-3/span), warhead strength 20, speed 32 -- briac Two leaping Dahuts. A thrush flying towards the east. Two bears waiting. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: read source file of .html
Gary Hawkins wrote: Along that line, I would like to be able to wind up with pages after retrieval as plain text without html tags, hopefully using a module. Here's a really quick way to do so using HTML::Parser, it can probably use some tweaking. Hope this helps, Briac #!/usr/bin/perl -w use strict; use HTML::Parser 3; use LWP::Simple; my $html = get(http://www.mit.edu;) or die Couldn't fetch the page; my $parser = HTML::Parser-new( unbroken_text = 1, ignore_elements = [qw( script head )], text_h = [ sub {print shift}, 'dtext'] )-parse($html)-eof(); __END__ -- briac A flying lark. Five trout swim in the pond. Four foxes under a she-oak. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Line Numbers and...
In article 000701c19bba$0af78320$1f58a9cb@S7575530, Leon wrote: { my $count = 0; open FILE, 'perl_script.pl' or die $!\n; while (FILE){ $count++; print Line $count: $_; }; close FILE; }; You could even do that in a one-liner: $ perl -pe'printf(%03i : , $.)' perl_script.pl or, under Windows: C:\ perl -peprintf('%03i : ', $.) perl_script.pl The $. variable hold the number of the current line being read. (see perldoc perlvar) -- briac Six darting carps. Joshu departs near a dojo. Five old men. A dove. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Switches
In article [EMAIL PROTECTED], Naveen Parmar wrote: Any site that provides details on the different command line switches? No need to waste bandwidth when all the relevant infos are on your system! :) perldoc perlrun -- briac Bankei departs under an oak tree. Ten bears eat under a she-oak. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: return code
In article [EMAIL PROTECTED], Ahmed Moustafa wrote: Hi All, I'm calling a Java application using system. How can I know the return code of the called Java application? perldoc -f system (...) The return value is the exit status of the program as returned by the wait call. To get the actual exit value divide by 256. See also the exec entry elsewhere in this document. You can check all the failure possibilities by inspecting $? like this: $exit_value = $? 8; $signal_num = $? 127; $dumped_core = $? 128; -- briac A leaping trout. Three foxes near the market-place. A lark nests. A lark sings. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IP address from the registry
Jorge Goncalvez wrote: Hi, Is there a way to obtain the IP address from the registry in Both Windows 98 and NT with Perl moduls. Dave Roth's GetIP script should do what you want, hopefully with a miminmum amount of tweaking: http://www.roth.net/perl/scripts/scripts.asp?GetIP.pl -- briac A pair of thrushes flying over the pool. Bankei under a maple. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cookies ...
Polikarpov Cyrill wrote: I'm working whith perl but I don't know how to work whith cookies. Give me please some tips for this one ... A good start would probably be to read the documentation of HTTP::Cookies perldoc HTTP::Cookies or http://search.cpan.org/doc/GAAS/libwww-perl-5.63/lib/HTTP/Cookies.pm The CGI modules also offers support of cookies and have good examples on how to use them in it documentation: perldoc CGI or http://search.cpan.org/doc/LDS/CGI.pm-2.79/CGI.pm (search for the section called HTTP Cookies) A good read is merlyn's Web Techniques, at least two of them deals directly with cookies: http://www.stonehenge.com/merlyn/WebTechniques/col61.html http://www.stonehenge.com/merlyn/WebTechniques/col32.html A lot of other articles are using Cookies too, and they're probably the best commented examples you could find. Hope this helps, Briac -- briac Two kingfishers flying towards the west. Master Po near the market-place. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Google-script, enhancements
In article 00c101c1993b$662efc40$b81411d5@pc2002, Henk Van Ess wrote: Dear all, I'm enhancing the Google-script, and would love to get an OUTPUT like this: http://www.google.com/search?q=leukas_qdr=m3 How do I get the FIXED value as_qdr=m3 after the VARIABLE q? I don't need a Prefix now, but a suffix. How do I enter this in Perl? You can change the line : print redirect(http://www.google.com/search?q=$prefix%20$search; ); To : print redirect( http://www.google.com/search?q=$prefix%20$searchas_qdr=m3; ); -- briac The Jade Emperor under an elm tree. A wolf walks beside a stream. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Parsing and regexp
Jorge Goncalvez wrote: Hi, I made a parsing of a file which contains : this: Adresse IP. . . . . . . . . : 155.132.48.23 like this to obtain the Ip adress. if ($_ =~/Adresse IP/) { $_ =~ s/.+://; $Subnet=$_; push @IPREAL, $_; $_=~ s/(\d+\.\d+\.\d+)\.\d+/$1.0/; push @IP, $_; It works but my problem is that parsing works only in french files, but I wanted to make it working in another language like for exemple English. I have IP Address. . . . . . . . . : 155.132.114.77 How can I improve my regexp if ($_ =~/Adresse IP/) to check the IP address indepentmently of the language (I know that the searched string contains always IP ) Something along those lines might work: #!/usr/bin/perl -w use strict; my (@IPREAL, @IP); while (DATA){ if ( /.*?IP.*?(?:\. )+:\s([0-9.]+)/ ){ my $ip = $1; push @IPREAL, $ip; $ip =~ s/(\d+\.\d+\.\d+)\.\d+/$1.0/; push @IP, $ip; } } print IPREAL: @IPREAL\n; print IP: @IP\n; __DATA__ Adresse IP. . . . . . . . . : 155.132.48.23 IP Address. . . . . . . . . : 155.135.48.23 Whatever language IP. . . . : 134.43.12.22 __END__ -- briac A pair of songbirds nest in the branches of a she-oak tree. A lark nests. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]