|
|
Up |
|
|
  |
Author: TravisTravis
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 |
|
  |
Author: PerlFAQ ServerPerlFAQ 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
|
|
  |
Author: GibberingGibbering
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 |
|
  |
Author: Mahesh AsolkarMahesh 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 |
|
  |
Author: PerlFAQ ServerPerlFAQ 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
|
|
  |
Author: ShaunJShaunJ
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 |
|
  |
Author: jomarbueyesjomarbueyes
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 |
|
  |
Author: PerlFAQ ServerPerlFAQ 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
|
|
  |
|
|
  |
|
|
  |
Author: DanishDanish
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 |
|
|
|
|
|
|