"How do I fetch a news article or the active newsgroups?" in perlfaq9

How do I fetch a news article or the active newsgroups? ... ::NNTPClient->new->list("newsgroups")'

"How do I substitute case insensitively on the LHS, but preserving case on the RHS?" in perlfaq6

# finish up with any remaining new (for when new is longer than old) if ($newlen > $oldlen) { ... } elsif ($state == 2) { substr($new, $oldlen) = uc(substr($new, $oldlen));

"How can I reliably rename a file?" in perlfaq5

) or system("mv", $old, $new); It may be more compelling to use the File::Copy module instead. ... You just copy to the new file to the new name (checking return values), then delete the old one.

"How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?" in perlfaq5

; open(NEW, "> $new") or die "can't open $new: $!" ... ; close(NEW) or die "can't close $new: $!"

"How can I split a [character] delimited string except when inside [character]? (Comma-separated files)" in perlfaq4

He suggests (assuming your string is contained in $text): @new = (); push(@new, $+) while ... | , }gx; push(@new, undef) if substr($text,-1,1) eq ','; If you want to represent quotation

"How stable is Perl?" in perlfaq1

Production releases, which incorporate bug fixes and new functionality, are widely tested before release ... invalidate a program written for an earlier version of perl (barring accidental bug fixes and the rare new

"What's the difference between dynamic and lexical (static) scoping? Between local() and my()?" in perlfaq7

local($x) saves away the old value of the global variable $x, and assigns a new value for the duration ... my($x) creates a new variable that is only visible in the current subroutine.

"What's wrong with always quoting "$vars"?" in perlfaq4

Think of it this way: double-quote expansion is used to produce new strings. ... Those should (in 99.8% of the cases) be the simpler and more direct: print $var; $new = $old

"What are the Perl newsgroups on USENET? Where do I post questions?" in perlfaq2

also USENET gateway to the mailing list used by the crack Perl development team (perl5-porters) at news ... :// .

"What is variable suicide and how can I prevent it?" in perlfaq7

} } T; print "Finally $f\n"; The $f that has "bar" added to it three times should be a new ... $f (my $f should create a new local variable each time through the loop).

"How do I make a temporary file name?" in perlfaq5

Use the new_tmpfile class method from the IO::File module to get a filehandle opened for reading and ... use IO::File; $fh = IO::File->new_tmpfile() or die "Unable to make new temporary file: $!

"Who supports Perl? Who develops it? Why is it free?" in perlfaq1

See perlhist (new as of 5.005) for Perl's milestone releases. ... You may snoop on pending developments via nntp:// and the Deja News archive

"How do I efficiently match many regular expressions at once?" in perlfaq6

As of the 5.005 release, there's a much better approach, one which makes use of the new qr// operator ... : # use spiffy new qr// operator, with /i flag even use 5.005; @popstates = qw(CO ON MI

"I put a regular expression into $/ but it didn't work. What's wrong?" in perlfaq6

$fh = new FileHandle "+<file"; ## Attach it to a "stream" object. ... use Net::Telnet; $file = new Net::Telnet (-fhopen => $fh); ## Search for the second line and

"Can I use perl to run a telnet or ftp session?" in perlfaq8

handshaking, then the standard dual-process approach will suffice: use IO::Socket; # new ... in 5.004 $handle = IO::Socket::INET->new('') || die "can't connect to

"How do I cross-reference my Perl programs?" in perlfaq3

The B::Xref module, shipped with the new, alpha-release Perl compiler (not the general distribution prior

"What is perl6?" in perlfaq1

interface to allow most XS modules to work unchanged, albeit perhaps without the efficiency that the new ... New features in Topaz are as yet undetermined, and will be addressed once compatibility and performance

"How do I shuffle an array randomly?" in perlfaq4

works using splice, randomly picking another element to swap the current element with: srand; @new ... = (); @old = 1 .. 10; # just a demo while (@old) { push(@new, splice(@old, rand @old

"How can I open a file with a leading ">" or trailing blanks?" in perlfaq5

; For more information, see also the new perlopentut if you have it (new for 5.006).

"Why doesn't open() return an error when a pipe open fails?" in perlfaq8

Because the pipe open takes place in two steps: first Perl calls fork() to start a new process, then ... this new process calls exec() to run the program you really wanted to open.

"How come when I open a file read-write it wipes it out?" in perlfaq5

; To open file for writing, create new file if needed or else truncate old file: open(FH, "> $path ... See also the new perlopentut if you have it (new for 5.006).

"How do I declare/create a structure?" in perlfaq7

Here's an example: $person = {}; # new anonymous hash $person->{AGE} = 24

"How can I comment out a large block of perl code?" in perlfaq7

You have to put a pod directive where the parser is expecting a new statement, not just in the middle

"How do I modify the shadow password file on a Unix system?" in perlfaq8

To change the file, make a new shadow password file (the format varies from system to system - see passwd

"How do I edit my .htpasswd and .htgroup files with Perl?" in perlfaq9

Here's an example: use HTTPD::UserAdmin (); HTTPD::UserAdmin ->new(DB => "/foo/.htpasswd

"How do I redefine a builtin function, operator, or method?" in perlfaq7

:-) If you want to override a predefined function, such as open(), then you'll have to import the new

"How do I temporarily block warnings?" in perlfaq7

A new use warnings pragma is in the works to provide finer control over all this.

"Where should I post source code?" in perlfaq2

If you're just looking for software, first use Alta Vista, Deja News, and search CPAN.

"Where can I get perl-mode for emacs?" in perlfaq3

You are probably using "main::foo" in new Perl code anyway, so this shouldn't be an issue.

"How do I install a CPAN module?" in perlfaq8

without dynamic loading, then you just need to replace step 3 (make) with make perl and you will get a new

"How do I read mail?" in perlfaq9

say which mail host to use $ENV{SMTPHOSTS} = ''; # create headers $header = new ...'); # create body $body = 'This is a test, ignore'; # create mail object $mail = new

"How do I decode or create those %-encodings on the web?" in perlfaq9


"What's the difference between calling a function as &foo and foo()?" in perlfaq7

When you call your function as &foo(), then you do get a new @_, but prototyping is still circumvented

"How do I automate an HTML form submission?" in perlfaq9

use HTTP::Request::Common qw(POST); use LWP::UserAgent; $ua = LWP::UserAgent->new(); my

"How can I lock a file?" in perlfaq5

For more information on file locking, see also "File Locking" in perlopentut if you have it (new for

"How can I use a filehandle indirectly?" in perlfaq5

(bless-able) $fh = *SOME_FH{IO}; # blessed IO::Handle from *SOME_FH typeglob Or to use the new ... $fh = IO::Handle->new(); Then use any of those as you would a normal filehandle.

"How do I debug my Perl programs?" in perlfaq3

It's full of gotchas for old and new Perl programmers, and even has sections for those of you who are

"When shouldn't I program in Perl?" in perlfaq1

The new, native-code compiler for Perl may eventually reduce the limitations given in the previous statement

"How do I fetch an HTML file?" in perlfaq9

defined $html or die "Can't fetch HTML from"; $ascii = HTML::FormatText->new

"Archives of comp.lang.perl.misc" in perlfaq2

Archives of comp.lang.perl.misc Have you tried Deja News or Alta Vista?

"Where do I get the include files to do ioctl() or syscall()?" in perlfaq8

MakeMaker for more information (in brief, just use make perl instead of a plain make to rebuild perl with a new

"Is Perl difficult to learn?" in perlfaq1

Don't forget the new perl modules, either.

"How do I send mail?" in perlfaq9

Or use the CPAN module Mail::Mailer: use Mail::Mailer; $mailer = Mail::Mailer->new(); $

"How do I handle linked lists?" in perlfaq4

could grow the list this way: my ($head, $tail); $tail = append($head, 1); # grow a new

"Does Perl have a year 2000 problem? Is Perl Y2K compliant?" in perlfaq4

See for a longer exposition.

"What modules and extensions are available for Perl? What is CPAN? What does CPAN/src/... mean?" in perlfaq2

wide web support; server and daemon utilities; archiving and compression; image manipulation; mail and news

"How can I convince my sysadmin/supervisor/employees to use version (5/5.005/Perl instead of some other language)?" in perlfaq1

In fact, many Unix vendors now ship Perl by default, and support is usually just a news-posting away,

"How do I read just one key without waiting for a return key?" in perlfaq8

$oterm, $echo, $noecho, $fd_stdin); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new

"How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?" in perlfaq5

isn't light-weight: use FileHandle; foreach $filename (@names) { my $fh = FileHandle->new

"How do I flush/unbuffer an output filehandle? Why must I do this?" in perlfaq5

$sock = IO::Socket::INET->new(PeerAddr => '', PeerPort

"How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regexp}?" in perlfaq7

get_rec { my $fh = shift; return scalar <$fh>; } If you're planning on generating new

"How can I read a single character from a file? From the keyboard?" in perlfaq5

echo, $noecho, $fd_stdin); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new