SEARCH RESULTS

FAQ

"How do I fetch/put an (S)FTP file?" in perlfaq9

How do I fetch/put an (S)FTP file?

"How do I strip blank space from the beginning/end of a string?" in perlfaq4

You can do that with a pair of substitutions: s/^\s+//; s/\s+$//; You can also write that as ... That might not matter to you, though: s/^\s+|\s+$//g; In this regular expression, the alternation

"What does it mean that regexes are greedy? How can I get around it?" in perlfaq6

An example: my $s1 = my $s2 = "I am very very cold"; $s1 =~ s/ve. ... *y //; # I am cold $s2 =~ s/ve.*?

"Why don't my <<HERE documents work?" in perlfaq4

:([^\w\s]+)(\s*).*\n)(?:\s*\g1\g2?. ... )/, ''); } s/^\s*?

"How do I change the Nth occurrence of something?" in perlfaq4

$count = 0; s{((whom?)ever)}{ ++$count == 5 # is it the 5th? ? ... :\w+\s+fish\s+){2}(\w+)\s+fish/i;

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

local $_ = ""; while( sysread FH, $_, 8192, length ) { while( s/^((?s).*?) ... s).*?)

"How do I test whether two arrays or hashes are equal?" in perlfaq4

cmpStr); my @a = my @b = ( "this", "that", [ "more", "stuff" ] ); printf "a and b contain %s ... "the same" : "different"; printf "a and b contain %s hashes\n", cmpStrHard(\%a, \%b) == 0 ?

"How can I hope to use regular expressions without creating illegible and unmaintainable code?" in perlfaq6

/x lets you turn this: s{<(?:[^>'"]*|".*?"|'.*?') ... For example, the s/// above uses braces as delimiters.

"How can I expand variables in text strings?" in perlfaq4

might even be able to get the job done with sprintf or printf: my $string = sprintf 'Say hello to %s ... \$(\w+)/$Replacements{$1}/g; $string =~ s/\$(\w+)/ exists $Replacements{$1} ?

"I'm having trouble matching over more than one line. What's wrong?" in perlfaq6

Read perlre to help you decide which of /s and /m (or both) you might want to use: /s allows dot to include ... END/sgm ) { # /s makes . cross line boundaries print "$1\n"; } }

"How do I capitalize all the words on one line?" in perlfaq4

How is Perl supposed to know not to capitalize that s after the apostrophe? ... You could try a regular expression: $string =~ s/ ( (^\w) #at the beginning

"How do I use a regular expression to strip C-style comments from a file?" in perlfaq6

For example, this one-liner perl -0777 -pe 's{/\*.*? ... this, created by Jeffrey Friedl and later modified by Fred Curtis. $/ = undef; $_ = <>; s#

"How can I quote a variable to use in a regex?" in perlfaq6

Remember, too, that the right-hand side of a s/// substitution is considered a double-quoted string ( ... "; $string =~ s/$regex/Polyp/; # $string is now "Polypacido P.

"Can I write useful Perl programs on the command line?" in perlfaq3

for(@ARGV) {print if -f && -T _}' * # remove (most) comments from C program perl -0777 -pe 's{ ... $s{$_}++&&push@m,$_;END{print"@m"}' OK, the last one was actually an Obfuscated Perl Contest entry.

"How do I get a file's timestamp in perl?" in perlfaq5

Here's an example: my $write_secs = (stat($file))[9]; printf "file %s updated at %s\n", $file

"How can I output my numbers with commas added?" in perlfaq5

$1,$2/; return $_; } This regex from Benjamin Goldberg will add commas to numbers: s/ ... =\d))/$1,/g; It is easier to see with comments: s/( ^[-+]?

"How do I sort an array by (anything)?" in perlfaq4

my @idx; for (@data) { my $item; ($item) = /\d+\s*(\S+)/; push @idx, uc($ ... (\S+)/)[0]) ] } @data; If you need to sort on several fields, the following paradigm is useful.

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

If the second argument to a piped open() contains shell metacharacters, perl fork()s, then exec()s a

"How do I determine whether a scalar is a number/whole/integer/float?" in perlfaq4

sub getnum { use POSIX qw(strtod); my $str = shift; $str =~ s/^\s+//; ... $str =~ s/\s+$//; $!

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

# Left padding a string with blanks (no truncation): my $padded = sprintf("%${pad_len}s", $ ... text); my $padded = sprintf("%*s", $pad_len, $text); # same thing # Right padding a string

More results found. Refine your search terms or show all FAQ results.

Functions

s///

s/// The substitution operator. See "Regexp Quote-Like Operators" in perlop.

stat - get a file's status information

S_IRWXU S_IRUSR S_IWUSR S_IXUSR S_IRWXG S_IRGRP S_IWGRP S_IXGRP S_IRWXO S_IROTH S_IWOTH S_IXOTH ... S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT # The following are

chmod - changes the permissions on a list of files

* constants from the Fcntl module: use Fcntl qw( :mode ); chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH ... |S_IXOTH, @executables; # Identical to the chmod 0755 of the example above.

getsockname - retrieve the sockaddr for a given socket

mysockaddr = getsockname($sock); my ($port, $myaddr) = sockaddr_in($mysockaddr); printf "Connect to %s ... [%s]\n", scalar gethostbyaddr($myaddr, AF_INET), inet_ntoa($myaddr);

substr - get or alter a portion of a string

my $s = "The black cat climbed the green tree"; my $color = substr $s, 4, 5; # black my ... the green tree my $tail = substr $s, -4; # tree my $z = substr $s, -4, 2;

redo - start this loop iteration over again

({.*}.*){.*}|$1 |) {} s|{.*}| |; if (s|{.*| |) { my $front = $_; ... s|^|$front\{|; redo LINE; } } } print

chop - remove the last character from a string

It is much more efficient than s/.$//s because it neither scans nor copies the string.

semop - SysV semaphore operations

Each semop structure can be generated with pack("s!3", $semnum, $semop, $semflag). ... example, the following code waits on semaphore $semnum of semaphore id $semid: my $semop = pack("s!

syscall - execute an arbitrary system call

syswrite function (or vice versa): require 'syscall.ph'; # may need to run h2ph my $s ... = "hi there\n"; syscall(SYS_write(), fileno(STDOUT), $s, length $s); Note that Perl supports passing

sprintf - formatted print into a string

universally-known conversions: %% a percent sign %c a character with the given number %s ... ', 12; # prints "< 12>" printf '<%-6s>', 12; # prints "<12 >" printf '<%06s>', 12; #

fc - return casefolded version of a string

feature 'unicode_strings", as lc does, with the single exception of fc of LATIN CAPITAL LETTER SHARP S ... Since that character itself folds to "s", the string of two of them together should be equivalent to

-X - a file test (-r, -x, etc)

-S File is a socket. -b File is a block special file. ... $file) + 1024 # probably wrong; same as -s($file + 1024) (-s $file) + 1024 # correct The interpretation

pack - convert a list into a binary representation

s A signed short (16-bit) value. S An unsigned short value. ... On unpacking, bits are converted to a string of 0s and 1s.

lc - return lower-case version of a string

For example, the lower case of LATIN CAPITAL LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII ... UTF-8 locale), the lower case of U+1E9E is itself, because 0xDF may not be LATIN SMALL LETTER SHARP S

semctl - SysV semaphore control operations

The ARG must consist of a vector of native short integers, which may be created with pack("s!"

values - return a list of the values in a hash

copied, which means modifying them will modify the contents of the hash: for (values %hash) { s/ ... foo/bar/g } # modifies %hash values for (@hash{keys %hash}) { s/foo/bar/g } # same Starting with

localtime - convert UNIX time into record or string using local time

date strings, try for example: use POSIX qw(strftime); my $now_string = strftime "%a %b %e %H:%M:%S ... # or for GMT formatted appropriately for your locale: my $now_string = strftime "%a %b %e %H:%M:%S

quotemeta - quote regular expression magic characters

fox'; $sentence =~ s{$substring}{big bad wolf}; Will cause $sentence to become 'The big bad wolf ... fox'; $sentence =~ s{\Q$substring\E}{big bad wolf}; Or: my $sentence = 'The quick brown fox

{pos() = 5}) or s//pos() = 5/e.

system - run a separate program

& 127) { printf "child died with signal %d, %s coredump\n", ($? & 127), ($?

More results found. Refine your search terms or show all function results.

Documentation

I18N::LangTags::Detect - detect the user's language preferences

I18N::LangTags::Detect::detect(); DESCRIPTION It is a common problem to want to detect what language(s)

encguess - guess character encodings of files

-s specify a list of "suspect encoding types" to test, separated by either : or , -S output a list ... encguess -s euc-jp,shiftjis,7bit-jis test.txt encguess -s euc-jp:shiftjis:7bit-jis test.txt Guess the

Test::Builder::IO::Scalar - A copy of IO::Scalar for Test::Builder

Newer versions of Perl simply use open()'s built in support. ... tell()s, it is still safer to explicitly seek-to-end before subsequent print()s.

Text::Balanced - Extract delimited text sequences from strings.

Improperly nested codeblock at %s A nested code block was found that started with a delimiter that ... Found invalid nested tag: %s extract_tagged found a nested tag that appeared in the "reject" list (

perlretut - Perl regular expressions tutorial

So be careful with nested '*''s, {n,m}'s, and '+''s. ... and s{}{}, and even s{}//.

Net::POP3 - Post Office Protocol 3 Client class (RFC1939)

POP3S or POP3+STARTTLS. A new Net::POP3 object must be created with the new method. ... Default - 110 for plain POP3 and 995 for POP3s (direct SSL).

perlvms - VMS-specific documentation for Perl

-S If the "-S" or -"S" switch is present and the script name does not contain a directory, then Perl ... statvfs, socketpair File tests The tests -b, -B, -c, -C, -d, -e, -f, -o, -M, -s, -S, -t, -T, and

sigtrap - Perl pragma to enable simple signal handling

handlers supplied by sigtrap itself (one which provides a Perl stack trace and one which simply die()s)

perldiag - various Perl diagnostics

'%c' allowed only after types %s in %s (F) The modifiers '!' ... Can't coerce %s to %s in %s (F) Certain types of SVs, in particular real symbol table entries (typeglobs

perlclib - Internal replacements for standard C library functions

(s1, s2) / strGT(s1,s2) strncmp(s1, s2, n) strnNE ... Strtod(s, &p) strtol(s, &p, n) Strtol(s, &p, b) strtoul(s, &p, n) Strtoul(s, &p,

Filter::Simple - Simplified source filtering

no\s+$caller\s*;\s*? ... BANG\s+BANG/die 'BANG' if \$BANG/g; } qr/^\s*GNAB\s+esu\s*;\s*?

Net::servent - by-name interface to Perl's built-in getserv*() functions

= getservbyname(shift || 'ftp') || die "no service"; printf "port for %s is %s, aliases are %s\n", ... $s->name, $s->port, "@{$s->aliases}"; use Net::servent qw(:FIELDS); getservbyname(shift || 'ftp') ||

perlrequick - Perl regular expressions quick start

such as s!!! ... and s{}{}, and even s{}//.

Thread::Semaphore - Thread-safe semaphores

$s->down_force(); # The default value for semaphore operations is 1 my $s = Thread::Semaphore->new($ ... initial_value); $s->down($down_value); $s->up($up_value); if ($s->down_nb($down_value)) { ...

perlrecharclass - Perl Regular Expression Character Classes

s) (and even globally within the scope of use re '/s'). ... s?

Win32API::File - Low-level access to Win32 system API calls for files/dirs.

CopyFile CopyFile( $sOldFileName, $sNewFileName, $bFailIfExists ) $sOldFileName is the path to the ... file data and some attributes to $sNewName and then deleting $sOldName.

perlperf - Perl Performance and Optimization Techniques

-\s*-\s*\[ ([^]]+) # date \]\s*"\w+\s* (\S+) ... # query [^"]+"\s* (\d+) # status \s+\S+\s+"[^"]*"\s+"

IPC::SysV - System V IPC constants and system calls

GETPID GETNCNT GETZCNT GETALL SETALL SEM_A SEM_R SEM_UNDO SHM_RDONLY SHM_RND SHMLBA and auxiliary ones S_IRUSR ... S_IWUSR S_IRWXU S_IRGRP S_IWGRP S_IRWXG S_IROTH S_IWOTH S_IRWXO but your system might have more.

perldtrace - Perl's support for DTrace

:*perl*::sub-entry { printf("%s::%s entered at %s line %d\n", copyinstr(arg3), copyinstr ... :*perl*::sub-return { printf("%s::%s returned at %s line %d\n", copyinstr(arg3), copyinstr

Fatal - Replace functions with equivalents which succeed or die

DIAGNOSTICS Bad subroutine name for Fatal: %s You've called Fatal with an argument that doesn't ... Internal error: %s You've found a bug in Fatal. Please report it using the perlbug command.

More results found. Refine your search terms or show all documentation results.

Perldeltas

"panic: attempt to call %s in %s" in perl589delta

panic: attempt to call %s in %s This new fatal error occurs when the ACL version file test operator

"New "read() on %s filehandle %s"" in perl581delta

New "read() on %s filehandle %s" You cannot read() (or sysread()) from a closed or unopened filehandle

"panic: sv_chop %s" in perl589delta

New or Changed Diagnostics panic: sv_chop %s This new fatal error occurs when the C routine Perl_sv_chop

"New "To%s: illegal mapping '%s'"" in perl581delta

New "To%s: illegal mapping '%s'" An illegal user-defined Unicode casemapping was specified.

"%s argument is not a HASH or ARRAY element or a subroutine" in perl589delta

%s argument is not a HASH or ARRAY element or a subroutine This error, thrown if an invalid argument

"Can't upgrade %s (%d) to %d" in perl589delta

Can't upgrade %s (%d) to %d Previously the internal error from the SV upgrade code was the less informative

"Cannot make the non-overridable builtin %s fatal" in perl589delta

Cannot make the non-overridable builtin %s fatal This error in Fatal previously did not show the name ... of the builtin in question (now represented by %s above).

"Unrecognized character '%s' in column %d" in perl589delta

Unrecognized character '%s' in column %d This error previously did not state the column.

"Changed "Invalid range "%s" in transliteration operator"" in perl581delta

Changed "Invalid range "%s" in transliteration operator" The old version Invalid [] range "%s"

"New "Newline in left-justified string for %s"" in perl581delta

New "Newline in left-justified string for %s" The padding spaces would appear after the newline, which

"Backslash no longer escapes colon in PATH for the -S switch" in perl5280delta

Backslash no longer escapes colon in PATH for the -S switch Previously the -S switch incorrectly treated

"Maximal count of pending signals (%s) exceeded" in perl589delta

Maximal count of pending signals (%s) exceeded This new fatal error occurs when the perl process has

"find2perl, s2p and a2p removal" in perl5220delta

Utility Changes find2perl, s2p and a2p removal The x2p/ directory has been removed from the Perl core ... This removes find2perl, s2p and a2p.

"[CVE-2018-6913] heap-buffer-overflow in S_pack_rec" in perl5262delta

[CVE-2018-6913] heap-buffer-overflow in S_pack_rec pack() could cause a heap buffer write overflow with

"[CVE-2018-6913] heap-buffer-overflow in S_pack_rec" in perl5244delta

[CVE-2018-6913] heap-buffer-overflow in S_pack_rec pack() could cause a heap buffer write overflow with

"[perl #115994] fix segv in regcomp.c:S_join_exact()" in perl5144delta

[perl #115994] fix segv in regcomp.c:S_join_exact() Under debugging builds, while marking optimised-out

"Invalid escape in the specified encoding in regexp; marked by <-- HERE in m/%s/" in perl589delta

Invalid escape in the specified encoding in regexp; marked by <-- HERE in m/%s/ New error, introduced

"[CVE-2018-18312] Heap-buffer-overflow write in S_regatom (regcomp.c)" in perl5281delta

[CVE-2018-18312] Heap-buffer-overflow write in S_regatom (regcomp.c) A crafted regular expression could

"[CVE-2018-18314] Heap-buffer-overflow write in S_regatom (regcomp.c)" in perl5263delta

[CVE-2018-18314] Heap-buffer-overflow write in S_regatom (regcomp.c) A crafted regular expression could

"[CVE-2018-18312] Heap-buffer-overflow write in S_regatom (regcomp.c)" in perl5263delta

[CVE-2018-18312] Heap-buffer-overflow write in S_regatom (regcomp.c) A crafted regular expression could

More results found. Refine your search terms or show all perldelta results.