SEARCH RESULTS

FAQ

"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 while preserving case on the RHS?" in perlfaq6

uc $new | (uc $1 ^ $1) . ... # finish up with any remaining new (for when new is longer than old) if ($newlen > $oldlen) {

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

) or system("mv", $old, $new); It may be more portable 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 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 do I use MIME to make an attachment to a mail message?" in perlfaq9

use MIME::Lite; ### Create a new multipart message: $msg = MIME::Lite->new( ... =>'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "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.

"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

"How do I convert between numeric representations?" in perlfaq4

; $dec = sprintf("%d", $int); Using Bit::Vector: use Bit::Vector; $vec = Bit::Vector->new ... Using Bit::Vector: $vec = Bit::Vector->new_Bin(32, "11011110101011011011111011101111"); $dec

"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

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

work 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

"What happens if I add or remove keys from a hash while iterating over it?" in perlfaq4

because that might cause a doubling of the hash table, in which half the entries get copied up to the new ... Even if the table doesn't double, there's no telling whether your new entry will be inserted before or

"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).

"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('www.perl.com:80') || die "can't connect to

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

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

If you don't have a modern enough Perl installed, use the new_tmpfile class method from the IO::File ... ) or die "Unable to make new temporary file: $!"

"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.6).

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

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

"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

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

See perlhist (new as of 5.005) for Perl's milestone releases. ... www.xray.mpe.mpg.de/mailing-lists/perl5-porters/ and http://archive.develooper.com/perl5-porters@perl.org/ or the news

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

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

"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.

"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 do I install a module from CPAN?" 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 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 http://www.perl.com/"; $ascii = HTML::FormatText->new

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

Support is usually just a news-posting away, if you can't find the answer in the comprehensive documentation ... In August 2000 in all Linux distributions a new security problem was found in the optional 'suidperl'

"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

might be able use the CPAN module Mail::Mailer: use Mail::Mailer; $mailer = Mail::Mailer->new

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

See http://language.perl.com/news/y2k.html for a longer exposition.

"How do I handle linked lists?" in perlfaq4

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

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

bless-able) $fh = *SOME_FH{IO}; # blessed IO::Handle from *SOME_FH typeglob Or, you can use the new ... use IO::Handle; # 5.004 or higher $fh = IO::Handle->new(); Then use any of those

"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 read a single character from a file? From the keyboard?" in perlfaq5

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

"How do I pad a string with blanks or pad a number with zeroes?" in perlfaq4

Left and right padding with any character, creating a new string: $padded = $pad_char x ( $pad_len

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

my $sock = IO::Socket::INET->new( 'www.example.com:80' ) ; $sock->autoflush();

"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 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 do I manipulate arrays of bits?" in perlfaq4

. $+[0] * 8; } Or use the CPAN module Bit::Vector: $vector = Bit::Vector->new($num_of_bits

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

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

"Is there an IDE or Windows Perl Editor?" in perlfaq3

in trying it out, firstly because strictly speaking it is not a vi clone, it is the real vi, or the new