comp.lang.perl.misc
  Home FAQ Contact Sign in
comp.lang.perl.misc only
 
Advanced search
April 2008
motuwethfrsasuw
 123456 14
78910111213 15
14151617181920 16
21222324252627 17
282930     18
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.perl.misc Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  Ignore empty lines and ones that start w/...         


Author: Travis
Date: Apr 15, 2008 22:55

While reading a file, ignoring empty lines seems pretty
straightforward, but how can I ignore a line that starts with
something like <-- which I use for comments.

ex:

-- Title -->
<-- Date -->
...
info to parse
...
6 Comments
  FAQ 9.8 How do I fetch an HTML file?         


Author: PerlFAQ Server
Date: Apr 15, 2008 18:03

This is an excerpt from the latest version perlfaq9.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

9.8: How do I fetch an HTML file?

One approach, if you have the lynx text-based HTML browser installed on
your system, is this:

$html_code = `lynx -source $url`;
$text_data = `lynx -dump $url`;

The libwww-perl (LWP) modules from CPAN provide a more powerful way to
do this. They don't require lynx, but like lynx, can still work through
proxies:

# simplest version
use LWP::Simple;
$content = get($URL);
Show full article (1.98Kb)
no comments
  Accessing a hash whose name is constructed         


Author: Gibbering
Date: Apr 15, 2008 12:46

I want to access some data from a hash, but want to build that hash's
name on the fly... here's the code:

%%hello = (a => 'doggy');
print ${'hell' . lc 'O'}{a};

does the trick as does:
print %%{'hell' . lc 'O'}->{a};

however, under "use strict", this fails, since %%hello isn't declared
with "my".

If I do put a my in front of the %%hello declaration, the print
statement gives me nothing.
I have a sinking suspicion that the above code is wrong, dangerous,
and error prone since I'm not even sure why it works.

What is the proper way to do such a thing?
5 Comments
  How to know if data is piped into my script         


Author: Mahesh Asolkar
Date: Apr 15, 2008 12:37

I have the following script:

-----
#!/usr/bin/perl

use strict;
use warnings;

my %%hist = ();
my @hist;

$hist{(split /\s+/)[3]}++
foreach (`$ENV{'SHELL'} -c history`);

print map {"$hist{$_} : $_\n"}
sort {$hist{$b} <=> $hist{$a}}
keys %%hist;
-----

I want to change it such that it uses '`$ENV{'SHELL'} -c history`'
only if nothing is piped into the script. If I call the script like:

%% myscript.pl

It should use '`$ENV{'SHELL'} -c history`'. However if it is called
like:

%% history | myscript.pl
Show full article (0.64Kb)
4 Comments
  FAQ 9.15 How do I parse a mail header?         


Author: PerlFAQ Server
Date: Apr 15, 2008 12:03

This is an excerpt from the latest version perlfaq9.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

9.15: How do I parse a mail header?

For a quick-and-dirty solution, try this solution derived from "split"
in perlfunc:

$/ = '';
$header = ;
$header =~ s/\n\s+/ /g; # merge continuation lines
%%head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header );

That solution doesn't do well if, for example, you're trying to maintain
all the Received lines. A more complete approach is to use the
Mail::Header module from CPAN (part of the MailTools package).

--------------------------------------------------------------------
Show full article (1.49Kb)
no comments
  Print a separator between each iteration of a foreach loop         


Author: ShaunJ
Date: Apr 15, 2008 10:24

I want to print a separator between each iteration of a foreach loop,
but not after the last element. How do I avoid printing the last
extraneous comma in the following code snippet?

foreach (@ARGV) {
print $_, ',';
}
print "\n";

In this simple example join ',' would suffice, but the real body of
the foreach loop is more complicated. What I want to do is something
like this:

foreach (@ARGV) {
print $_;
print ',' unless last_element;
}
print "\n";

Thanks,
Shaun
12 Comments
  Can "perldoc" take input from a pipe?         


Author: jomarbueyes
Date: Apr 15, 2008 10:05

Dear All,

Is there a way to make perldoc take its input from stdin? I tried the
obvious:
command | perldoc
but it didn't work.

My idea is to embed "pod" documentation in source code written in
Fortran and C++, then write a perl script that will search for the pod
documentation, remove the comment marks, and pipe the resulting output
to something that can format perlpod.

I'm using Perl 5.8.8 under Linix and Mac OS X (10.5 Intel and 10.4
PPC) and Perl 5.004_05 under Irix 6.4.

Thanks in advance for any help,

Jomar
4 Comments
  FAQ 9.9 How do I automate an HTML form submission?         


Author: PerlFAQ Server
Date: Apr 15, 2008 06:03

This is an excerpt from the latest version perlfaq9.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

9.9: How do I automate an HTML form submission?

If you are doing something complex, such as moving through many pages
and forms or a web site, you can use "WWW::Mechanize". See its
documentation for all the details.

If you're submitting values using the GET method, create a URL and
encode the form using the "query_form" method:

use LWP::Simple;
use URI::URL;

my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
$content = get($url);

If you're using the POST method, create your own user agent and encode
the content appropriately.
Show full article (1.92Kb)
no comments
  moving unused of a website         


Author: Marek
Date: Apr 15, 2008 04:46

Hello all,

I am a perl beginner. So patience please!

I wrote a perl-script to find all unused pix of a web site. Now I
would like to move all those 168! pix from the folder pix to the
folder pix_out keeping the same hierarchy as in the original folder.
That means:

/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/thumbnails/
tn_munich28.jpg

should be renamed to:

/Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos/
thumbnails/tn_munich28.jpg

Only one folder is changing his name: pix -> pix_out And this with all
my 168 unused pix in different folders.

I was hoping, that the rename function would create the missing
folders, doing:

rename "/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
thumbnails/tn_munich28.jpg", "/Users/xxx/Documents/webpages/
www.myproject.de/pix_out/fotos/thumbnails/tn_munich28.jpg";
Show full article (1.48Kb)
18 Comments
  Creating PDF documents from a Perl Program...         


Author: Danish
Date: Apr 15, 2008 04:11

Hi there,

I'm working on a database driven website and I need to output data in
PDF format. The database handling is all written in Perl so I'd prefer
to stick to Perl if possible, hence my question in this newsgroup!

I've done some research and come up with a couple of ideas: PDF on the
Fly from Nottingham University and a module listed on CPAN called PDF-
Create-0.08 by Markus Baertschi.

What I'd like to know is if anyone out there has experience of doing
this kind of thing. What method they used and what problems they hit,
if any.

Thanks in advance,

Nigel
6 Comments
 
1 2