Markdown Format | JSON API | MCP Server Tool
List directory contents.
ls -1ls {{-a|--all}}ls {{-F|--classify}}ls {{-la|-l --all}}ls {{-lh|-l --human-readable}}ls {{-lSR|-lS --recursive}}ls {{-ltr|-lt --reverse}}ls {{-d|--directory}} */Found in /usr/share/perl/5.34/pod/perlfaq4.pod Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)? For the long explanation, see David Goldberg's "What Every Computer Scientist Should Know About Floating-Point Arithmetic" (<http://web.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf>). Internally, your computer represents floating-point numbers in binary. Digital (as in powers of two) computers cannot store all numbers exactly. Some real numbers lose precision in the process. This is a problem with how computers store numbers and affects all computer languages, not just Perl. perlnumber shows the gory details of number representations and conversions. To limit the number of decimal places in your numbers, you can use the "printf" or "sprintf" function. See "Floating-point Arithmetic" in perlop for more details. printf "%.2f", 10/3; my $number = sprintf "%.2f", 10/3; How can I output Roman numerals? Get the <http://www.cpan.org/modules/by-module/Roman> module. How do I expand function calls in a string? (contributed by brian d foy) This is documented in perlref, and although it's not the easiest thing to read, it does work. In each of these examples, we call the function inside the braces used to dereference a reference. If we have more than one return value, we can construct and dereference an anonymous array. In this case, we call the function in list context. print "The time values are @{ [localtime] }.\n"; If we want to call the function in scalar context, we have to do a bit more work. We can really have any code we like inside the braces, so we simply have to end with the scalar reference, although how you do that is up to you, and you can use code inside the braces. Note that the use of parens creates a list context, so we need "scalar" to force the scalar context on the function: print "The time is ${\(scalar localtime)}.\n" print "The time is ${ my $x = localtime; \$x }.\n"; If your function already returns a reference, you don't need to create the reference yourself. sub timestamp { my $t = localtime; \$t } print "The time is ${ timestamp() }.\n"; The "Interpolation" module can also do a lot of magic for you. You can specify a variable name, in this case "E", to set up a tied hash that does the interpolation for you. It has several other methods to do this as well. use Interpolation E => 'eval'; print "The time values are $E{localtime()}.\n"; In most cases, it is probably easier to simply use string concatenation, which also forces scalar context. print "The time is " . localtime() . ".\n"; How do I keep persistent data across program calls? For some specific applications, you can use one of the DBM modules. See AnyDBM_File. More generically, you should consult the FreezeThaw or Storable modules from CPAN. Starting from Perl 5.8, Storable is part of the standard distribution. Here's one example using Storable's "store" and "retrieve" functions: use Storable; store(\%hash, "filename"); # later on... $href = retrieve("filename"); # by ref %hash = %{ retrieve("filename") }; # direct to hash Found in /usr/share/perl/5.34/pod/perlfaq8.pod How do I trap control characters/signals? You don't actually "trap" a control character. Instead, that character generates a signal which is sent to your terminal's currently foregrounded process group, which you then trap in your process. Signals are documented in "Signals" in perlipc and the section on "Signals" in the Camel. You can set the values of the %SIG hash to be the functions you want to handle the signal. After perl catches the signal, it looks in %SIG for a key with the same name as the signal, then calls the subroutine value for that key. # as an anonymous subroutine $SIG{INT} = sub { syswrite(STDERR, "ouch\n", 5 ) }; # or a reference to a function $SIG{INT} = \&ouch; # or the name of the function as a string $SIG{INT} = "ouch"; Perl versions before 5.8 had in its C source code signal handlers which would catch the signal and possibly run a Perl function that you had set in %SIG. This violated the rules of signal handling at that level causing perl to dump core. Since version 5.8.0, perl looks at %SIG after the signal has been caught, rather than while it is being caught. Previous versions of this answer were incorrect. Why doesn't open() return an error when a pipe open fails? If the second argument to a piped "open()" contains shell metacharacters, perl "fork()"s, then "exec()"s a shell to decode the metacharacters and eventually run the desired program. If the program couldn't be run, it's the shell that gets the message, not Perl. All your Perl program can find out is whether the shell itself could be successfully started. You can still capture the shell's STDERR and check it for error messages. See "How can I capture STDERR from an external command?" elsewhere in this document, or use the IPC::Open3 module. If there are no shell metacharacters in the argument of "open()", Perl runs the command directly, without using the shell, and can correctly report whether the command started. Found in /usr/share/perl/5.34/pod/perlfaq9.pod How do I extract URLs? HTML::SimpleLinkExtor will extract URLs from HTML, it handles anchors, images, objects, frames, and many other tags that can contain a URL. If you need anything more complex, you can create your own subclass of HTML::LinkExtor or HTML::Parser. You might even use HTML::SimpleLinkExtor as an example for something specifically suited to your needs. You can use URI::Find or URL::Search to extract URLs from an arbitrary text document.
Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 18:35 @216.73.216.151 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)