[12493] in Perl-Users-Digest
Perl-Users Digest, Issue: 6094 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 22 13:07:18 1999
Date: Tue, 22 Jun 99 10:01:33 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 22 Jun 1999 Volume: 8 Number: 6094
Today's topics:
How to find and delete or replace a section in a line <v0xman@yahoo.com>
Re: How to find and delete or replace a section in a li <tchrist@mox.perl.com>
Re: how to sort uniq <cassell@mail.cor.epa.gov>
Re: Interpreting MS-ASCII - anyone have a filter? <uri@sysarch.com>
Re: linux passwords <tchrist@mox.perl.com>
Re: Multiple Fax Server <anfi@bigfoot.com>
Re: Need help with #exec cgi <martin@adoma.se>
Re: Newbie - Perl books - which to get? <upsetter@ziplink.net>
Ouput Binary <netsmith@well.com>
Re: Ouput Binary <anfi@bigfoot.com>
Re: Ouput Binary <tchrist@mox.perl.com>
Re: Please Help with Perl 5 <cassell@mail.cor.epa.gov>
Re: Sending a mail from LOTUS NOTE (winNT) <cassell@mail.cor.epa.gov>
Re: Simple Question (I think) (Larry Rosler)
Re: Simple Question (I think) (Greg Bacon)
Re: Strip off file name by s/\\(.*)$// does not work (brian d foy)
Using MD5 hash in a regex <kevin.porter@fast.no>
Re: Using MD5 hash in a regex (Mark-Jason Dominus)
Re: www.economite.com <cassell@mail.cor.epa.gov>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 22 Jun 1999 13:33:17 -0300
From: "Vox" <v0xman@yahoo.com>
Subject: How to find and delete or replace a section in a line
Message-Id: <rWOb3.160419$r_1.34643763@newscontent-02.sprint.ca>
If I have a string such as:
"ineedhelpinfindinganddeletingasectioninastring"
and the section of this line above that I want to delete or replace is
'findinganddeleting'
Does anyone have any suggestions?
------------------------------
Date: 22 Jun 1999 10:45:08 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to find and delete or replace a section in a line
Message-Id: <376fbd94@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
Cursed to torture himself and others using the risible Microsoft Outlook
Express 5.00.2014.211 as a "news" "reader", "Vox" <v0xman@yahoo.com>
writes in comp.lang.perl.misc:
:If I have a string such as:
:
:"ineedhelpinfindinganddeletingasectioninastring"
:
:and the section of this line above that I want to delete or replace is
:'findinganddeleting'
:Does anyone have any suggestions?
% man perlop
NAME
perlop - Perl operators and precedence
SYNOPSIS
Perl operators have the following associativity and precedence,
listed from highest precedence to lowest. Operators borrowed
from C keep the same precedence relationship with each other,
even where C's precedence is slightly screwy. (This makes
learning Perl easier for C folks.) With very few exceptions,
these all operate on scalar values only, not array values.
[deletia]
Regexp Quote-Like Operators
Here are the quote-like operators that apply to pattern matching
and related activities.
?PATTERN?
This is just like the `/pattern/' search, except that it
matches only once between calls to the reset() operator.
This is a useful optimization when you want to see only
the first occurrence of something in each file of a set
of files, for instance. Only `??' patterns local to the
current package are reset.
while (<>) {
if (?^$?) {
# blank line between header and body
}
} continue {
reset if eof; # clear ?? status for next file
}
This usage is vaguely depreciated, which means it just
might possibly be removed in some distant future version
of Perl, perhaps somewhere around the year 2168.
m/PATTERN/cgimosx
/PATTERN/cgimosx
Searches a string for a pattern match, and in scalar
context returns true if it succeeds, false if it fails.
If no string is specified via the `=~' or `!~' operator,
the $_ string is searched. (The string specified with
`=~' need not be an lvalue--it may be the result of an
expression evaluation, but remember the `=~' binds
rather tightly.) See also the perlre manpage. See the
perllocale manpage for discussion of additional
considerations that apply when `use locale' is in
effect.
Options are:
c Do not reset search position on a failed match when /g is in effect.
g Match globally, i.e., find all occurrences.
i Do case-insensitive pattern matching.
m Treat string as multiple lines.
o Compile pattern only once.
s Treat string as single line.
x Use extended regular expressions.
If "/" is the delimiter then the initial `m' is
optional. With the `m' you can use any pair of non-
alphanumeric, non-whitespace characters as delimiters.
This is particularly useful for matching path names that
contain "/", to avoid LTS (leaning toothpick syndrome).
If "?" is the delimiter, then the match-only-once rule
of `?PATTERN?' applies. If "'" is the delimiter, no
interpolation is performed on the PATTERN.
PATTERN may contain variables, which will be
interpolated (and the pattern recompiled) every time the
pattern search is evaluated, except for when the
delimiter is a single quote. (Note that `$)' and `$|'
might not be interpolated because they look like end-of-
string tests.) If you want such a pattern to be compiled
only once, add a `/o' after the trailing delimiter. This
avoids expensive run-time recompilations, and is useful
when the value you are interpolating won't change over
the life of the script. However, mentioning `/o'
constitutes a promise that you won't change the
variables in the pattern. If you change them, Perl won't
even notice. See also the section on "/" in the qr
manpage.
If the PATTERN evaluates to the empty string, the last
*successfully* matched regular expression is used
instead.
If the `/g' option is not used, `m//' in list context
returns a list consisting of the subexpressions matched
by the parentheses in the pattern, i.e., (`$1', `$2',
`$3'...). (Note that here `$1' etc. are also set, and
that this differs from Perl 4's behavior.) When there
are no parentheses in the pattern, the return value is
the list `(1)' for success. With or without parentheses,
an empty list is returned upon failure.
Examples:
open(TTY, '/dev/tty');
<TTY> =~ /^y/i && foo(); # do foo if desired
if (/Version: *([0-9.]*)/) { $version = $1; }
next if m#^/usr/spool/uucp#;
# poor man's grep
$arg = shift;
while (<>) {
print if /$arg/o; # compile only once
}
if (($F1, $F2, $Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))
This last example splits $foo into the first two words
and the remainder of the line, and assigns those three
fields to $F1, $F2, and $Etc. The conditional is true if
any variables were assigned, i.e., if the pattern
matched.
The `/g' modifier specifies global pattern matching--
that is, matching as many times as possible within the
string. How it behaves depends on the context. In list
context, it returns a list of the substrings matched by
any capturing parentheses in the regular expression. If
there are no parentheses, it returns a list of all the
matched strings, as if there were parentheses around the
whole pattern.
In scalar context, each execution of `m//g' finds the
next match, returning true if it matches, and false if
there is no further match. The position after the last
match can be read or set using the pos() function; see
the "pos" entry in the perlfunc manpage. A failed match
normally resets the search position to the beginning of
the string, but you can avoid that by adding the `/c'
modifier (e.g. `m//gc'). Modifying the target string
also resets the search position.
You can intermix `m//g' matches with `m/\G.../g', where
`\G' is a zero-width assertion that matches the exact
position where the previous `m//g', if any, left off.
The `\G' assertion is not supported without the `/g'
modifier. (Currently, without `/g', `\G' behaves just
like `\A', but that's accidental and may change in the
future.)
Examples:
# list context
($one,$five,$fifteen) = (`uptime` =~ /(\d+\.\d+)/g);
# scalar context
$/ = ""; $* = 1; # $* deprecated in modern perls
while (defined($paragraph = <>)) {
while ($paragraph =~ /[a-z]['")]*[.!?]+['")]*\s/g) {
$sentences++;
}
}
print "$sentences\n";
# using m//gc with \G
$_ = "ppooqppqq";
while ($i++ < 2) {
print "1: '";
print $1 while /(o)/gc; print "', pos=", pos, "\n";
print "2: '";
print $1 if /\G(q)/gc; print "', pos=", pos, "\n";
print "3: '";
print $1 while /(p)/gc; print "', pos=", pos, "\n";
}
The last example should print:
1: 'oo', pos=4
2: 'q', pos=5
3: 'pp', pos=7
1: '', pos=7
2: 'q', pos=8
3: '', pos=8
A useful idiom for `lex'-like scanners is `/\G.../gc'.
You can combine several regexps like this to process a
string part-by-part, doing different actions depending
on which regexp matched. Each regexp tries to match
where the previous one leaves off.
$_ = <<'EOL';
$url = new URI::URL "http://www/"; die if $url eq "xXx";
EOL
LOOP:
{
print(" digits"), redo LOOP if /\G\d+\b[,.;]?\s*/gc;
print(" lowercase"), redo LOOP if /\G[a-z]+\b[,.;]?\s*/gc;
print(" UPPERCASE"), redo LOOP if /\G[A-Z]+\b[,.;]?\s*/gc;
print(" Capitalized"), redo LOOP if /\G[A-Z][a-z]+\b[,.;]?\s*/gc;
print(" MiXeD"), redo LOOP if /\G[A-Za-z]+\b[,.;]?\s*/gc;
print(" alphanumeric"), redo LOOP if /\G[A-Za-z0-9]+\b[,.;]?\s*/gc;
print(" line-noise"), redo LOOP if /\G[^A-Za-z0-9]+/gc;
print ". That's all!\n";
}
Here is the output (split into several lines):
line-noise lowercase line-noise lowercase UPPERCASE line-noise
UPPERCASE line-noise lowercase line-noise lowercase line-noise
lowercase lowercase line-noise lowercase lowercase line-noise
MiXeD line-noise. That's all!
q/STRING/
`'STRING''
A single-quoted, literal string. A backslash represents
a backslash unless followed by the delimiter or another
backslash, in which case the delimiter or backslash is
interpolated.
$foo = q!I said, "You said, 'She said it.'"!;
$bar = q('This is it.');
$baz = '\n'; # a two-character string
qq/STRING/
"STRING"
A double-quoted, interpolated string.
$_ .= qq
(*** The previous line contains the naughty word "$1".\n)
if /\b(tcl|java|python)\b/i; # :-)
$baz = "\n"; # a one-character string
qr/STRING/imosx
This operators quotes--and compiles--its *STRING* as a
regular expression. *STRING* is interpolated the same
way as *PATTERN* in `m/PATTERN/'. If "'" is used as the
delimiter, no interpolation is done. Returns a Perl
value which may be used instead of the corresponding
`/STRING/imosx' expression.
For example,
$rex = qr/my.STRING/is;
s/$rex/foo/;
is equivalent to
s/my.STRING/foo/is;
The result may be used as a subpattern in a match:
$re = qr/$pattern/;
$string =~ /foo${re}bar/; # can be interpolated in other patterns
$string =~ $re; # or used standalone
$string =~ /$re/; # or this way
Since Perl may compile the pattern at the moment of
execution of qr() operator, using qr() may have speed
advantages in some situations, notably if the result of
qr() is used standalone:
sub match {
my $patterns = shift;
my @compiled = map qr/$_/i, @$patterns;
grep {
my $success = 0;
foreach my $pat @compiled {
$success = 1, last if /$pat/;
}
$success;
} @_;
}
Precompilation of the pattern into an internal
representation at the moment of qr() avoids a need to
recompile the pattern every time a match `/$pat/' is
attempted. (Perl has many other internal optimizations,
but none would be triggered in the above example if we
did not use qr() operator.)
Options are:
i Do case-insensitive pattern matching.
m Treat string as multiple lines.
o Compile pattern only once.
s Treat string as single line.
x Use extended regular expressions.
See the perlre manpage for additional information on
valid syntax for STRING, and for a detailed look at the
semantics of regular expressions.
qx/STRING/
`STRING`
A string which is (possibly) interpolated and then
executed as a system command with `/bin/sh' or its
equivalent. Shell wildcards, pipes, and redirections
will be honored. The collected standard output of the
command is returned; standard error is unaffected. In
scalar context, it comes back as a single (potentially
multi-line) string. In list context, returns a list of
lines (however you've defined lines with $/ or
$INPUT_RECORD_SEPARATOR).
Because backticks do not affect standard error, use
shell file descriptor syntax (assuming the shell
supports this) if you care to address this. To capture a
command's STDERR and STDOUT together:
$output = `cmd 2>&1`;
To capture a command's STDOUT but discard its STDERR:
$output = `cmd 2>/dev/null`;
To capture a command's STDERR but discard its STDOUT
(ordering is important here):
$output = `cmd 2>&1 1>/dev/null`;
To exchange a command's STDOUT and STDERR in order to
capture the STDERR but leave its STDOUT to come out the
old STDERR:
$output = `cmd 3>&1 1>&2 2>&3 3>&-`;
To read both a command's STDOUT and its STDERR
separately, it's easiest and safest to redirect them
separately to files, and then read from those files when
the program is done:
system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");
Using single-quote as a delimiter protects the command
from Perl's double-quote interpolation, passing it on to
the shell instead:
$perl_info = qx(ps $$); # that's Perl's $$
$shell_info = qx'ps $$'; # that's the new shell's $$
How that string gets evaluated is entirely subject to
the command interpreter on your system. On most
platforms, you will have to protect shell metacharacters
if you want them treated literally. This is in practice
difficult to do, as it's unclear how to escape which
characters. See the perlsec manpage for a clean and safe
example of a manual fork() and exec() to emulate
backticks safely.
On some platforms (notably DOS-like ones), the shell may
not be capable of dealing with multiline commands, so
putting newlines in the string may not get you what you
want. You may be able to evaluate multiple commands in a
single line by separating them with the command
separator character, if your shell supports that (e.g.
`;' on many Unix shells; `&' on the Windows NT `cmd'
shell).
Beware that some command shells may place restrictions
on the length of the command line. You must ensure your
strings don't exceed this limit after any necessary
interpolations. See the platform-specific release notes
for more details about your particular environment.
Using this operator can lead to programs that are
difficult to port, because the shell commands called
vary between systems, and may in fact not be present at
all. As one example, the `type' command under the POSIX
shell is very different from the `type' command under
DOS. That doesn't mean you should go out of your way to
avoid backticks when they're the right way to get
something done. Perl was made to be a glue language, and
one of the things it glues together is commands. Just
understand what you're getting yourself into.
See the section on "I/O Operators" for more discussion.
qw/STRING/
Evaluates to a list of the words extracted out of
STRING, using embedded whitespace as the word
delimiters. It can be understood as being roughly
equivalent to:
split(' ', q/STRING/);
the difference being that it generates a real list at
compile time. So this expression:
qw(foo bar baz)
is exactly equivalent to the list:
('foo', 'bar', 'baz')
Some frequently seen examples:
use POSIX qw( setlocale localeconv )
@EXPORT = qw( foo bar baz );
A common mistake is to try to separate the words with
comma or to put comments into a multi-line `qw'-string.
For this reason, the -w switch (that is, the `$^W'
variable) produces warnings if the STRING contains the
"," or the "#" character.
s/PATTERN/REPLACEMENT/egimosx
Searches a string for a pattern, and if found, replaces
that pattern with the replacement text and returns the
number of substitutions made. Otherwise it returns false
(specifically, the empty string).
If no string is specified via the `=~' or `!~' operator,
the `$_' variable is searched and modified. (The string
specified with `=~' must be scalar variable, an array
element, a hash element, or an assignment to one of
those, i.e., an lvalue.)
If the delimiter chosen is a single quote, no
interpolation is done on either the PATTERN or the
REPLACEMENT. Otherwise, if the PATTERN contains a $ that
looks like a variable rather than an end-of-string test,
the variable will be interpolated into the pattern at
run-time. If you want the pattern compiled only once the
first time the variable is interpolated, use the `/o'
option. If the pattern evaluates to the empty string,
the last successfully executed regular expression is
used instead. See the perlre manpage for further
explanation on these. See the perllocale manpage for
discussion of additional considerations that apply when
`use locale' is in effect.
Options are:
e Evaluate the right side as an expression.
g Replace globally, i.e., all occurrences.
i Do case-insensitive pattern matching.
m Treat string as multiple lines.
o Compile pattern only once.
s Treat string as single line.
x Use extended regular expressions.
Any non-alphanumeric, non-whitespace delimiter may
replace the slashes. If single quotes are used, no
interpretation is done on the replacement string (the
`/e' modifier overrides this, however). Unlike Perl 4,
Perl 5 treats backticks as normal delimiters; the
replacement text is not evaluated as a command. If the
PATTERN is delimited by bracketing quotes, the
REPLACEMENT has its own pair of quotes, which may or may
not be bracketing quotes, e.g., `s(foo)(bar)' or
`s<foo>/bar/'. A `/e' will cause the replacement portion
to be interpreted as a full-fledged Perl expression and
eval()ed right then and there. It is, however, syntax
checked at compile-time.
Examples:
s/\bgreen\b/mauve/g; # don't change wintergreen
$path =~ s|/usr/bin|/usr/local/bin|;
s/Login: $foo/Login: $bar/; # run-time pattern
($foo = $bar) =~ s/this/that/; # copy first, then change
$count = ($paragraph =~ s/Mister\b/Mr./g); # get change-count
$_ = 'abc123xyz';
s/\d+/$&*2/e; # yields 'abc246xyz'
s/\d+/sprintf("%5d",$&)/e; # yields 'abc 246xyz'
s/\w/$& x 2/eg; # yields 'aabbcc 224466xxyyzz'
s/%(.)/$percent{$1}/g; # change percent escapes; no /e
s/%(.)/$percent{$1} || $&/ge; # expr now, so /e
s/^=(\w+)/&pod($1)/ge; # use function call
# expand variables in $_, but dynamics only, using
# symbolic dereferencing
s/\$(\w+)/${$1}/g;
# /e's can even nest; this will expand
# any embedded scalar variable (including lexicals) in $_
s/(\$\w+)/$1/eeg;
# Delete (most) C comments.
$program =~ s {
/\* # Match the opening delimiter.
.*? # Match a minimal number of characters.
\*/ # Match the closing delimiter.
} []gsx;
s/^\s*(.*?)\s*$/$1/; # trim white space in $_, expensively
for ($variable) { # trim white space in $variable, cheap
s/^\s+//;
s/\s+$//;
}
s/([^ ]*) *([^ ]*)/$2 $1/; # reverse 1st two fields
Note the use of $ instead of \ in the last example.
Unlike sed, we use the \<*digit*> form in only the left
hand side. Anywhere else it's $<*digit*>.
Occasionally, you can't use just a `/g' to get all the
changes to occur that you might want. Here are two
common cases:
# put commas in the right places in an integer
1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g;
# expand tabs to 8-column spacing
1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;
tr/SEARCHLIST/REPLACEMENTLIST/cdsUC
y/SEARCHLIST/REPLACEMENTLIST/cdsUC
Transliterates all occurrences of the characters found
in the search list with the corresponding character in
the replacement list. It returns the number of
characters replaced or deleted. If no string is
specified via the =~ or !~ operator, the $_ string is
transliterated. (The string specified with =~ must be a
scalar variable, an array element, a hash element, or an
assignment to one of those, i.e., an lvalue.)
A character range may be specified with a hyphen, so
`tr/A-J/0-9/' does the same replacement as
`tr/ACEGIBDFHJ/0246813579/'. For sed devotees, `y' is
provided as a synonym for `tr'. If the SEARCHLIST is
delimited by bracketing quotes, the REPLACEMENTLIST has
its own pair of quotes, which may or may not be
bracketing quotes, e.g., `tr[A-Z][a-z]' or `tr(+\-
*/)/ABCD/'.
Note also that the whole range idea is rather unportable
between character sets--and even within character sets
they may cause results you probably didn't expect. A
sound principle is to use only ranges that begin from
and end at either alphabets of equal case (a-e, A-E), or
digits (0-4). Anything else is unsafe. If in doubt,
spell out the character sets in full.
Options:
c Complement the SEARCHLIST.
d Delete found but unreplaced characters.
s Squash duplicate replaced characters.
U Translate to/from UTF-8.
C Translate to/from 8-bit char (octet).
If the `/c' modifier is specified, the SEARCHLIST
character set is complemented. If the `/d' modifier is
specified, any characters specified by SEARCHLIST not
found in REPLACEMENTLIST are deleted. (Note that this is
slightly more flexible than the behavior of some tr
programs, which delete anything they find in the
SEARCHLIST, period.) If the `/s' modifier is specified,
sequences of characters that were transliterated to the
same character are squashed down to a single instance of
the character.
If the `/d' modifier is used, the REPLACEMENTLIST is
always interpreted exactly as specified. Otherwise, if
the REPLACEMENTLIST is shorter than the SEARCHLIST, the
final character is replicated till it is long enough. If
the REPLACEMENTLIST is empty, the SEARCHLIST is
replicated. This latter is useful for counting
characters in a class or for squashing character
sequences in a class.
The first `/U' or `/C' modifier applies to the left side
of the translation. The second one applies to the right
side. If present, these modifiers override the current
utf8 state.
Examples:
$ARGV[1] =~ tr/A-Z/a-z/; # canonicalize to lower case
$cnt = tr/*/*/; # count the stars in $_
$cnt = $sky =~ tr/*/*/; # count the stars in $sky
$cnt = tr/0-9//; # count the digits in $_
tr/a-zA-Z//s; # bookkeeper -> bokeper
($HOST = $host) =~ tr/a-z/A-Z/;
tr/a-zA-Z/ /cs; # change non-alphas to single space
tr [\200-\377]
[\000-\177]; # delete 8th bit
tr/\0-\xFF//CU; # change Latin-1 to Unicode
tr/\0-\x{FF}//UC; # change Unicode to Latin-1
If multiple transliterations are given for a character,
only the first one is used:
tr/AAA/XYZ/
will transliterate any A to X.
Because the transliteration table is built at compile
time, neither the SEARCHLIST nor the REPLACEMENTLIST are
subjected to double quote interpolation. That means that
if you want to use variables, you must use an eval():
eval "tr/$oldlist/$newlist/";
die $@ if $@;
eval "tr/$oldlist/$newlist/, 1" or die $@;
--
Real programmers can write assembly code in any language. :-)
--Larry Wall in <8571@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Tue, 22 Jun 1999 09:57:45 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: how to sort uniq
Message-Id: <376FC089.3D390BE0@mail.cor.epa.gov>
xin zhou wrote:
>
> It seems the built-in sort function does not provide csh's sort -u.
sort is not a function of csh. It is an entire, separate
program which one can call using csh.. or sh.. or Perl.. or...
> As a new perl user, I had to write a block to achieve the effect. Can you
> experienced guys write one of those crytic one-liners to do it?
You might want to go look in the FAQ and see the already-short
code listed therein. It's in perlfaq4. Or use perldoc's
-q option [just don't tell TomC you're using it :-].
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 22 Jun 1999 12:46:39 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Interpreting MS-ASCII - anyone have a filter?
Message-Id: <x7aets89ow.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
>> "\x91" => '`',
>> "\x92" => "'",
LR> Having just used this program on some Redmondware output, I would now
LR> change that one to '´', to match the backtick "\x91" better. Some
LR> of the others might use some more thought too. I didn't look into the
LR> substitutions when I massaged the program.
this is a tricky call. you fixed our paper that way and the ' (single
quote) char after translation to ´ is leaning way too far right
for my taste. maybe just converting it to ' is ok.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 22 Jun 1999 10:11:57 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: linux passwords
Message-Id: <376fb5cd@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
Tom Phoenix <rootbeer@redcat.com> writes:
:Rewriting the /etc/passwd file. See the docs, FAQs, and newsgroups
:about Linux and the passwd file for more information. Cheers!
Tom, please give precise references to your referenced references if
you ever post this kind of thing again.
--tom
--
"Grant me the serenity to accept the things I cannot change, the courage
to change the things I can, and the wisdom to hide the bodies of the
people that I had to kill because they pissed me off." --Anonymous
------------------------------
Date: Tue, 22 Jun 1999 18:26:07 +0200
From: Andrzej Filip <anfi@bigfoot.com>
Subject: Re: Multiple Fax Server
Message-Id: <376FB91F.46B3B590@bigfoot.com>
Darren Boyle wrote:
> I am being converted by a friend to using Linux rather than NT, since I
> understand that Linux is more stable, which is very desirable for my needs.
>
> I am constructing a multiple server fax system, consisting of 15 fax
> servers each with 8 modems connected. I have found a Linux program called
> Hylafax which can be found at ftp.sgi.com and would like to use this
> rather than a similar product (called BroadFax) on NT.
>
> The Linux software is great for a single user system to desktop fax, but
> what the NT product offers is a way of distributing the database of fax
> numbers between the 15 machines automatically.
>
> I've been told that a fairly straightforward Perl script should be able
> to add this missing feature, but I have not got a clue on how to do it
> myself.
>
> I can offer payment to anyone who can help me with this problem.
One of countless possible solutions:
Put your database as a page on WWW server (e.g. Apache)
Make fax servers periodically check if it has changed and
download it after a change is detected.
You need a small modification of surl script from "Perl Cookbook"
section 20.8 example 20-6 (1/3 of a page)
Books web page: http://www.ora.com/catalog/cookbook/
Examples: ftp://ftp.oreilly.com/published/oreilly/perl/cookbook/
So, download the examples (less than 200 KB) and find the script.
P.S.
You may use pgp to encrypt the data on the page.
--
Andrzej (Andrew) A. Filip fax: +1(801)327-6278
mailto:anfi@bigfoot.com http://www.bigfoot.com/~anfi
Postings: http://www.deja.com/profile.xp?author=Andrzej%20Filip&ST=PS
------------------------------
Date: Tue, 22 Jun 1999 18:30:02 +0100
From: "Martin Quensel" <martin@adoma.se>
Subject: Re: Need help with #exec cgi
Message-Id: <7koes8$bp6$1@cubacola.tninet.se>
Dimensions skrev i meddelandet ...
>I am running a "exec cgi" (SSI) as:
>
><!--#exec cgi="/cgi-bin/myscript.cgi"-->
>
>I have not being able to get it to work with parameters such as:
>
><!--#exec cgi="/cgi-bin/myscript.cgi?mydata1"-->
><!--#exec cgi="/cgi-bin/myscript.cgi?mydata2"-->
>etc...
>
>Can this type of script take them? What am I missing?
Yes, myscript.cgi is a well known parameter taker.
In fact it is even in the guinnes book of records for being the script that
gobbles up the most parameters.
Maybee you should try it with parameters like:
?is_this_a_perl_question?
?why_dont_you_ask_your_ISP_why?
Good luck
Martin Quensel
------------------------------
Date: Tue, 22 Jun 1999 16:12:24 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: Newbie - Perl books - which to get?
Message-Id: <IBOb3.933$7X1.237295@news.shore.net>
Rhonda Nowak <rmn@itol.com> wrote:
: Beginner Level -
: Learning Perl (2nd Edition) - Randal L. Schwartz
: Teach Yourself Perl 5 in 21 Days - David Till
You can't go wrong with Randal's book. Anyone considering paying money
for the second book should read this web page first:
http://xenu.phys.uit.no/~tom/TYP21D.html
I haven't read the book myself, but if it's half as bad as the same
publisher's (Sams.net) book on CGI programming, it's really really bad.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Tue, 22 Jun 1999 09:19:03 -0700
From: William Smith <netsmith@well.com>
Subject: Ouput Binary
Message-Id: <376FB774.1BCA921D@well.com>
I am reading in some strings from a text file, some of which are
numbers.
Then I am writing some of this data to an output file, but I need some
of
the numbers converted to binary format eg. input text of "257" needs to
written out as two bytes: 01 01
How do I do this? I don't see any discussion of writing out binary data
in my
Learning Perl by o'Reilly.
Thanks.
-- William Smith
------------------------------
Date: Tue, 22 Jun 1999 18:28:42 +0200
From: Andrzej Filip <anfi@bigfoot.com>
Subject: Re: Ouput Binary
Message-Id: <376FB9BA.B463D8A1@bigfoot.com>
William Smith wrote:
> I am reading in some strings from a text file, some of which are
> numbers.
> Then I am writing some of this data to an output file, but I need some
> of
> the numbers converted to binary format eg. input text of "257" needs to
> written out as two bytes: 01 01
> How do I do this? I don't see any discussion of writing out binary data
> in my Learning Perl by o'Reilly.
Use pack function to generate binary dat and than use print
to write the data to a file.
(Use binmode for portability)
--
Andrzej (Andrew) A. Filip fax: +1(801)327-6278
mailto:anfi@bigfoot.com http://www.bigfoot.com/~anfi
Postings: http://www.deja.com/profile.xp?author=Andrzej%20Filip&ST=PS
------------------------------
Date: 22 Jun 1999 10:34:44 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Ouput Binary
Message-Id: <376fbb24@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
Cursed to torture comp.lang.perl.misc with Mozilla 4.6 (Macintosh; I;
PPC), netsmith@well.com writes:
:I am reading in some strings from a text file, some of which are
:numbers. [THIS LINE WAS WRAPPED BY YOUR BROKEN NEWSREADER]
:Then I am writing some of this data to an output file, but I need some
:of [THIS LINE WAS WRAPPED BY YOUR BROKEN NEWSREADER]
:the numbers converted to binary format eg. input text of "257" needs to
:written out as two bytes: 01 01
:How do I do this? I don't see any discussion of writing out binary data
:in my [THIS LINE WAS WRAPPED BY YOUR BROKEN NEWSREADER]
:Learning Perl by o'Reilly.
:Thanks.
% man 3pl pack
NAME
pack - convert a list into a binary representation
SYNOPSIS
pack TEMPLATE,LIST
DESCRIPTION
Takes a list of values and packs it into a binary structure,
returning the string containing the structure. The TEMPLATE is a
sequence of characters that give the order and type of values,
as follows:
a A string with arbitrary binary data, will be null padded.
A An ascii string, will be space padded.
Z A null terminated (asciz) string, will be null padded.
b A bit string (ascending bit order, like vec()).
B A bit string (descending bit order).
h A hex string (low nybble first).
H A hex string (high nybble first).
c A signed char value.
C An unsigned char value. Only does bytes. See U for Unicode.
s A signed short value.
S An unsigned short value.
(This 'short' is _exactly_ 16 bits, which may differ from
what a local C compiler calls 'short'.)
i A signed integer value.
I An unsigned integer value.
(This 'integer' is _at_least_ 32 bits wide. Its exact
size depends on what a local C compiler calls 'int',
and may even be larger than the 'long' described in
the next item.)
l A signed long value.
L An unsigned long value.
(This 'long' is _exactly_ 32 bits, which may differ from
what a local C compiler calls 'long'.)
n A short in "network" (big-endian) order.
N A long in "network" (big-endian) order.
v A short in "VAX" (little-endian) order.
V A long in "VAX" (little-endian) order.
(These 'shorts' and 'longs' are _exactly_ 16 bits and
_exactly_ 32 bits, respectively.)
q A signed quad (64-bit) value.
Q An unsigned quad value.
(Available only if your system supports 64-bit integer values
_and_ if Perl has been compiled to support those.
Causes a fatal error otherwise.)
f A single-precision float in the native format.
d A double-precision float in the native format.
p A pointer to a null-terminated string.
P A pointer to a structure (fixed-length string).
u A uuencoded string.
U A Unicode character number. Encodes to UTF-8 internally.
Works even if C<use utf8> is not in effect.
w A BER compressed integer. Its bytes represent an unsigned
integer in base 128, most significant digit first, with as
few digits as possible. Bit eight (the high bit) is set
on each byte except the last.
x A null byte.
X Back up a byte.
@ Null fill to absolute position.
[etc]
--
And I haven't even touched on I/O performance. It doesn't do much good to
have a Gigaflop on your desk if you are still trying to feed it with a
Megabyte/sec I/O system. :-) --Patrick F. McGehearty
------------------------------
Date: Tue, 22 Jun 1999 09:10:36 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: Ron Lukawitski <luka@islandnet.com>
Subject: Re: Please Help with Perl 5
Message-Id: <376FB57C.84F2E359@mail.cor.epa.gov>
[courtesy cc to poster]
Ron Lukawitski wrote:
> I'm in real need of some serious help and hoping that I can find it here. I
> need to know if Perl 5 is capable of compiling the information from the
> enclosed e-mail responses to a musicians (Bass Players)
Yes. easily. In fact, as we say in the Perl community,
There's More Than One Way To Do It (TMTOWTDI).
> survey that I am conducting on the internet. I have well over 1'000
> responses and they all pretty much look like the 2 samples below.
> I need Perl to compile the following:
>
> fretted/fretless: (choose) FRETTED or FRETLESS
> bass : (choose) 4, 5 or 6 string bass
> name : (choose) any text
> acoustic : (choose) YES or NO
>
> I'll end up with 12 catagories and 2 extra (one for total responses and the
> other for (name:) those that double on other instruments.
> I'm new to Perl programming and would really appreciate all the help I can
Okay, then I guess you'll want to read about if-then-else
statements, and about hashes. Those will let you tally your
survey results. You might consider constructs like:
if ($response =~ m/FRETTED/i) {
$frets{fretted}++ ;
}
else {
$frets{fretless}++ ;
}
And you'll want to read up on the pieces you see here.
Variable names. ++ which increments by 1, as in C.
The pattern match operator m// and its /i option. The
=~ operator which tells the match operator what to work
on (we call it pattern binding). The hash %frets used
above (even though I have a '$' in the code for reasons
that will become clear when you read about them).
> get. I just bought the latest Perl 5 For Dummies which I really
> enjoy.
Sorry to hear that. It's not a good book. It may be enough
to get you interested, but it has a lot of mistakes that more
seasoned Perlites can see. You might want to hop over to
http://www.netcat.co.uk/rob/perl/win32perltut.html
and work through his tutorial. And you'll want to learn to
use the extensive docs which come with Perl. I've heard a
rumor that Perl For Dummies comes with a semi-Perl which does
not have all the standard modules and is missing all the
documentation.. and is not the most recent version anyway.
You might opt to go to www.activestate.com and grab a free
copy of real Perl for win32 (which installs like a charm and
also puts access to the docs on your Start Menu).
> THANKS..Ron Lukawitski
> http://www.islandnet.com/~luka/lessbass.htm
>
> S A M P L E
>
> ","nobody@islandnet.com","nobody@islandnet.com","SMTP","luka@islandnet.com",
> "luka@islandnet.com","SMTP",,,,,,,,,"Normal",,"Normal"
> "Form Results","Date : Fri Jun 18 22:09:46 1999
> Remote Host : dyn3247a.dialin.rad.net.id
> Email : nobody@islandnet.com
> fretted/fretless: FRETTED
> bass : 4string
> name :
> acoustic : YES
Okay, having seen a piece of your inputs, you'll also want to
read about open() [to open a file], while (<FILE>) [to read the
lines], close() [to close the file when you're done], and
the $/ variable [setting $/ = "" will let Perl drink in your
input file a paragraph at a time, so you can read an entire
form and work on it more easily].
Be sure to start each program with:
#!/usr/bin/perl -w
The path isn't right for you, but make sure you've got 'perl'
and '-w' in there. That way Perl will give you error messages
about your code, thus helping you find your mistakes before
you try to run this in production mode.
When you get some code written, if you have some problems,
feel free to post the part giving you trouble, with errors
you got, and what went right/wrong, and you should get some
more assistance then.
"Have the appropriate amount of fun." - Larry Wall
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 22 Jun 1999 09:41:19 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Sending a mail from LOTUS NOTE (winNT)
Message-Id: <376FBCAF.D33B5CFA@mail.cor.epa.gov>
Tom Phoenix wrote:
>
> Maybe someone in a newsgroup about mail, lotus notes, or Windows could
> tell you. Good luck!
And you could try the Perl-Win32-users listserv, which can be
subscribed to by going to
http://www.activestate.com/support/mailing_lists.htm
I know that Lotus Notes has been mentioned there recently..
I think when Amine posted news about the new Win32::MAPI
module...
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 22 Jun 1999 08:59:28 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Simple Question (I think)
Message-Id: <MPG.11d952b57f314a91989c1b@nntp.hpl.hp.com>
In article <7knb1k$mql$1@plonk.apk.net> on Tue, 22 Jun 1999 03:09:14 -
0400, Jody Fedor <JFedor@datacom-css.com> says...
...
> Mike, you can slurp the file into a variable.
>
> open (LOGS,"transfer_log") || die "Cannot open file transfer_log";
> while ($rec=<LOGS>) {$log .=$rec};
> print $log;
> close (LOGS);
>
> This might be "Perl Baby-Talk" but it will get the job done. I'm sure Larry
> (Rosler) might have a million better ways to do this, he is the King of
> Simplicity.
No, the Forrest Gump of Simplicity.
$rec = do { local $/; <LOGS> };
And don't forget to include $! in the 'open' error message.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 22 Jun 1999 16:09:56 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Simple Question (I think)
Message-Id: <7kocgk$2c4$1@info2.uah.edu>
In article <MPG.11d952b57f314a91989c1b@nntp.hpl.hp.com>,
lr@hpl.hp.com (Larry Rosler) writes:
: In article <7knb1k$mql$1@plonk.apk.net> on Tue, 22 Jun 1999 03:09:14 -
: 0400, Jody Fedor <JFedor@datacom-css.com> says...
: > This might be "Perl Baby-Talk" but it will get the job done. I'm sure Larry
: > (Rosler) might have a million better ways to do this, he is the King of
: > Simplicity.
:
: No, the Forrest Gump of Simplicity.
:
: $rec = do { local $/; <LOGS> };
To think some people say you need the File::Slurp module to do this.
Sigh. :-(
Greg
--
Cancelling other people's articles is juvenile. Threatening electronic
warfare over the Usenet is imbecilic. Repeat after me: " The netnews is not
real life. It's just 1s and 0s. It isn't that big a deal." Then go take a
walk outside and try to gain some perspective. -- Spaf
------------------------------
Date: Tue, 22 Jun 1999 12:32:06 -0400
From: brian@pm.org (brian d foy)
Subject: Re: Strip off file name by s/\\(.*)$// does not work
Message-Id: <brian-ya02408000R2206991232060001@news.panix.com>
In article <3773a911.7303377@news.skynet.be>, bart.lateur@skynet.be (Bart Lateur) posted:
> Franz GEIGER wrote:
>
> >I thought "s/\\(.*)$//" would do it. I read this as "find a backslash
> >followed by zero or more characters, but begin searching from the end of the
> >string".
>
> Nope. Match the first backslash and everything (anything) following it,
> up to the end.
i don't think about this because i use File::Basename ;)
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: Tue, 22 Jun 1999 17:04:08 -0400
From: kev <kevin.porter@fast.no>
Subject: Using MD5 hash in a regex
Message-Id: <376FFA48.2216E21@fast.no>
Hi,
I'm using MD5::hash() to check whther a web page has been changed since
my User Agent's last visit.
I am trying to compare the new MD5 hash with the previous MD5 hash, ie:
if ( $lastchksum !~ /$newchksum/ ) { $changed = 1; }
Can I escape the characters of the hash somehow so that my program will
not bomb out with:
/wT~)&akA.JF6/: unmatched () in regexp at chk.pl line 42
when the hash contains characters that have a special meaning in
regexes?
Thanks alot,
- Kev
------------------------------
Date: Tue, 22 Jun 1999 16:58:53 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Using MD5 hash in a regex
Message-Id: <7kofbb$cd3$1@monet.op.net>
In article <376FFA48.2216E21@fast.no>, kev <kevin.porter@fast.no> wrote:
>I am trying to compare the new MD5 hash with the previous MD5 hash, ie:
>if ( $lastchksum !~ /$newchksum/ ) { $changed = 1; }
Don't use a regex. Use the `ne' operator.
>if ( $lastchksum ne $newchksum ) { $changed = 1; }
>
>Can I escape the characters of the hash somehow so that my program will
>not bomb out with:
Wrong question.
------------------------------
Date: Tue, 22 Jun 1999 09:38:22 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: www.economite.com
Message-Id: <376FBBFE.C5F483AD@mail.cor.epa.gov>
kkling@economite.com wrote:
>
> http://www.economite.com
>
> The Linux Revolution
Anyone interested can complain to abuse@rcn.com
Boy, I didn't realize that someone could get me to think a
bad thought about Linux...
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 6094
**************************************