[11372] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4972 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 11:27:34 1999

Date: Fri, 26 Feb 99 08:26:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 26 Feb 1999     Volume: 8 Number: 4972

Today's topics:
        FAQ 9.20: How do I read mail?   <perlfaq-suggestions@perl.com>
        FAQ 9.21: How do I find out my hostname/domainname/IP a <perlfaq-suggestions@perl.com>
        FAQ 9.22: How do I fetch a news article or the active n <perlfaq-suggestions@perl.com>
        FAQ 9.2: How can I get better error messages from a CGI <perlfaq-suggestions@perl.com>
        FAQ 9.3: How do I remove HTML from a string?   <perlfaq-suggestions@perl.com>
    Re: FAQ 9.3: How do I remove HTML from a string? <ebohlman@netcom.com>
        FAQ 9.4: How do I extract URLs?   <perlfaq-suggestions@perl.com>
        FAQ 9.5: How do I download a file from the user's machi <perlfaq-suggestions@perl.com>
        FAQ 9.6: How do I make a pop-up menu in HTML?   <perlfaq-suggestions@perl.com>
        FAQ 9.7: How do I fetch an HTML file?   <perlfaq-suggestions@perl.com>
        FAQ 9.8: How do I automate an HTML form submission?   <perlfaq-suggestions@perl.com>
        FAQ 9.9: How do I decode or create those %-encodings on <perlfaq-suggestions@perl.com>
        file and directories <gpcu.mwagley@gcnet.com>
    Re: file and directories (Greg Bacon)
    Re: File Upload via HTTP progress indicator squid@fish.net
        File::stat->mode? <dkoleary@tako.wwa.com>
    Re: File::stat->mode? <tchrist@mox.perl.com>
    Re: File::stat->mode? (Doug O'Leary)
        files <singh5@students.uiuc.edu>
    Re: files (Andrew M. Langmead)
        Finding the week day. (Mauro Sanna)
    Re: Finding the week day. (Ronald J Kimball)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 24 Feb 1999 06:46:34 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.20: How do I read mail?  
Message-Id: <36d402ba@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I read mail?

    Use the Mail::Folder module from CPAN (part of the MailFolder package)
    or the Mail::Internet module from CPAN (also part of the MailTools
    package).

       # sending mail
        use Mail::Internet;
        use Mail::Header;
        # say which mail host to use
        $ENV{SMTPHOSTS} = 'mail.frii.com';
        # create headers
        $header = new Mail::Header;
        $header->add('From', 'gnat@frii.com');
        $header->add('Subject', 'Testing');
        $header->add('To', 'gnat@frii.com');
        # create body
        $body = 'This is a test, ignore';
        # create mail object
        $mail = new Mail::Internet(undef, Header => $header, Body => \[$body]);
        # send it
        $mail->smtpsend or die;

    Often a module is overkill, though. Here's a mail sorter.

        #!/usr/bin/perl 
        # bysub1 - simple sort by subject
        my(@msgs, @sub);
        my $msgno = -1;
        $/ = '';                    # paragraph reads
        while (<>) {
            if (/^From/m) {
                /^Subject:\s*(?:Re:\s*)*(.*)/mi;
                $sub[++$msgno] = lc($1) || '';
            }
            $msgs[$msgno] .= $_;
        } 
        for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) {
            print $msgs[$i];
        }

    Or more succinctly,

        #!/usr/bin/perl -n00
        # bysub2 - awkish sort-by-subject
        BEGIN { $msgno = -1 }
        $sub[++$msgno] = (/^Subject:\s*(?:Re:\s*)*(.*)/mi)[0] if /^From/m;
        $msg[$msgno] .= $_;
        END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] }

-- 
Weinberg's Second Law: If builders built buildings the way programmers
write programs, the first woodpecker to come along would destroy civilization.


------------------------------

Date: 24 Feb 1999 06:54:48 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.21: How do I find out my hostname/domainname/IP address?  
Message-Id: <36d404a8@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I find out my hostname/domainname/IP address?

    The normal way to find your own hostname is to call the ``hostname`'
    program. While sometimes expedient, this has some problems, such as not
    knowing whether you've got the canonical name or not. It's one of those
    tradeoffs of convenience versus portability.

    The Sys::Hostname module (part of the standard perl distribution) will
    give you the hostname after which you can find out the IP address
    (assuming you have working DNS) with a gethostbyname() call.

        use Socket;
        use Sys::Hostname;
        my $host = hostname();
        my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));

    Probably the simplest way to learn your DNS domain name is to grok it
    out of /etc/resolv.conf, at least under Unix. Of course, this assumes
    several things about your resolv.conf configuration, including that it
    exists.

    (We still need a good DNS domain name-learning method for non-Unix
    systems.)

-- 
    "Perl5, surprisingly, makes it very easy to do OO programming.  I suspect
    that it does this much better than Larry ever intended."
	--Dean Roehrich in <1994Oct5.140720.1511@driftwood.cray.com>


------------------------------

Date: 24 Feb 1999 06:55:26 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.22: How do I fetch a news article or the active newsgroups?  
Message-Id: <36d404ce@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

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

    Use the Net::NNTP or News::NNTPClient modules, both available from CPAN.
    This can make tasks like fetching the newsgroup list as simple as:

        perl -MNews::NNTPClient
          -e 'print News::NNTPClient->new->list("newsgroups")'

-- 
Basically, avoid comments. If your code needs a comment to be understood,
it would be better to rewrite it so it's easier to understand.  --Rob Pike


------------------------------

Date: 23 Feb 1999 12:44:59 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.2: How can I get better error messages from a CGI program?  
Message-Id: <36d3053b@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I get better error messages from a CGI program?

    Use the CGI::Carp module. It replaces `warn' and `die', plus the normal
    Carp modules `carp', `croak', and `confess' functions with more verbose
    and safer versions. It still sends them to the normal server error log.

        use CGI::Carp;
        warn "This is a complaint";
        die "But this one is serious";

    The following use of CGI::Carp also redirects errors to a file of your
    choice, placed in a BEGIN block to catch compile-time warnings as well:

        BEGIN {
            use CGI::Carp qw(carpout);
            open(LOG, ">>/var/local/cgi-logs/mycgi-log")
                or die "Unable to append to mycgi-log: $!\n";
            carpout(*LOG);
        }

    You can even arrange for fatal errors to go back to the client browser,
    which is nice for your own debugging, but might confuse the end user.

        use CGI::Carp qw(fatalsToBrowser);
        die "Bad error here";

    Even if the error happens before you get the HTTP header out, the module
    will try to take care of this to avoid the dreaded server 500 errors.
    Normal warnings still go out to the server error log (or wherever you've
    sent them with `carpout') with the application name and date stamp
    prepended.

-- 
    In general, they do what you want, unless you want consistency.
            --Larry Wall in the perl man page


------------------------------

Date: 23 Feb 1999 13:45:04 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.3: How do I remove HTML from a string?  
Message-Id: <36d31350@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I remove HTML from a string?

    The most correct way (albeit not the fastest) is to use HTML::Parse from
    CPAN (part of the HTML-Tree package on CPAN).

    Many folks attempt a simple-minded regular expression approach, like
    `s/<.*?>//g', but that fails in many cases because the tags may continue
    over line breaks, they may contain quoted angle-brackets, or HTML
    comment may be present. Plus folks forget to convert entities, like
    `&lt;' for example.

    Here's one "simple-minded" approach, that works for most files:

        #!/usr/bin/perl -p0777
        s/<(?:[^>'"]*|(['"]).*?\1)*>//gs

    If you want a more complete solution, see the 3-stage striphtml program
    in
    http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz .

    Here are some tricky cases that you should think about when picking a
    solution:

        <IMG SRC = "foo.gif" ALT = "A > B">

        <IMG SRC = "foo.gif" 
             ALT = "A > B">

        <!-- <A comment> -->

        <script>if (a<b && a>c)</script>

        <# Just data #>

        <![INCLUDE CDATA [ >>>>>>>>>>>> ]]>

    If HTML comments include other tags, those solutions would also break on
    text like this:

        <!-- This section commented out.
            <B>You can't see me!</B>
        -->

-- 
It is Unix.  It is possible to overcome any number of these bogus features. --pjw


------------------------------

Date: Wed, 24 Feb 1999 02:46:38 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: FAQ 9.3: How do I remove HTML from a string?
Message-Id: <ebohlmanF7n11r.63w@netcom.com>

Tom Christiansen <perlfaq-suggestions@perl.com> wrote:
: (This excerpt from perlfaq9 - Networking 
:     ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
: part of the standard set of documentation included with every 
: valid Perl distribution, like the one on your system.
: See also http://language.perl.com/newdocs/pod/perlfaq9.html
: if your negligent system adminstrator has been remiss in his duties.)

:   How do I remove HTML from a string?

:     The most correct way (albeit not the fastest) is to use HTML::Parse from
:     CPAN (part of the HTML-Tree package on CPAN).

HTML::Parse is now deprecated in favor of HTML::Parser.


------------------------------

Date: 23 Feb 1999 14:45:07 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.4: How do I extract URLs?  
Message-Id: <36d32163@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I extract URLs?

    A quick but imperfect approach is

        #!/usr/bin/perl -n00
        # qxurl - tchrist@perl.com
        print "$2\n" while m{
            < \s*
              A \s+ HREF \s* = \s* (["']) (.*?) \1
            \s* >
        }gsix;

    This version does not adjust relative URLs, understand alternate bases,
    deal with HTML comments, deal with HREF and NAME attributes in the same
    tag, or accept URLs themselves as arguments. It also runs about 100x
    faster than a more "complete" solution using the LWP suite of modules,
    such as the
    http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz
    program.

-- 
    X-Windows: Power tools for power losers.
	--Jamie Zawinski


------------------------------

Date: 23 Feb 1999 15:45:09 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.5: How do I download a file from the user's machine?  How do I open a file on another machine?  
Message-Id: <36d32f75@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I download a file from the user's machine?  How do I open a file on another machine?

    In the context of an HTML form, you can use what's known as
    multipart/form-data encoding. The CGI.pm module (available from CPAN)
    supports this in the start_multipart_form() method, which isn't the same
    as the startform() method.

-- 
    If I allowed "next $label" then I'd also have to allow "goto $label",
    and I don't think you really want that...  :-) [now works in perl5!]
            --Larry Wall in <1991Mar11.230002.27271@jpl-devvax.jpl.nasa.gov>


------------------------------

Date: 23 Feb 1999 16:45:11 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.6: How do I make a pop-up menu in HTML?  
Message-Id: <36d33d87@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I make a pop-up menu in HTML?

    Use the <SELECT> and <OPTION> tags. The CGI.pm module (available from
    CPAN) supports this widget, as well as many others, including some that
    it cleverly synthesizes on its own.

-- 
    Some are born to perl, some achieve perl, and some have perl
    thrust upon them.  


------------------------------

Date: 23 Feb 1999 17:45:13 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.7: How do I fetch an HTML file?  
Message-Id: <36d34b99@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I fetch an HTML file?

    One approach, if you have the lynx text-based HTML browser installed on
    your system, is this:

        $html_code = `lynx -source $url`;
        $text_data = `lynx -dump $url`;

    The libwww-perl (LWP) modules from CPAN provide a more powerful way to
    do this. They work through proxies, and don't require lynx:

        # simplest version
        use LWP::Simple;
        $content = get($URL);

        # or print HTML from a URL
        use LWP::Simple;
        getprint "http://www.sn.no/libwww-perl/";

        # or print ASCII from HTML from a URL
        # also need HTML-Tree package from CPAN
        use LWP::Simple;
        use HTML::Parse;
        use HTML::FormatText;
        my ($html, $ascii);
        $html = get("http://www.perl.com/");
        defined $html
            or die "Can't fetch HTML from http://www.perl.com/";
        $ascii = HTML::FormatText->new->format(parse_html($html));
        print $ascii;

-- 
And don't tell me there isn't one bit of difference between null and space,
because that's exactly how much difference there is.  :-)
        --Larry Wall in <10209@jpl-devvax.JPL.NASA.GOV>


------------------------------

Date: 23 Feb 1999 18:45:15 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.8: How do I automate an HTML form submission?  
Message-Id: <36d359ab@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I automate an HTML form submission?

    If you're submitting values using the GET method, create a URL and
    encode the form using the `query_form' method:

        use LWP::Simple;
        use URI::URL;

        my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
        $url->query_form(module => 'DB_File', readme => 1);
        $content = get($url);

    If you're using the POST method, create your own user agent and encode
    the content appropriately.

        use HTTP::Request::Common qw(POST);
        use LWP::UserAgent;

        $ua = LWP::UserAgent->new();
        my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
                       [ module => 'DB_File', readme => 1 ];
        $content = $ua->request($req)->as_string;

-- 
This is a "feature" of dynamic scoping when used with call-by-reference.
Don't do that.  :-)


------------------------------

Date: 23 Feb 1999 19:45:17 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 9.9: How do I decode or create those %-encodings on the web?  
Message-Id: <36d367bd@csnews>

(This excerpt from perlfaq9 - Networking 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:39:48 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq9.html
if your negligent system adminstrator has been remiss in his duties.)

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

    Here's an example of decoding:

        $string = "http://altavista.digital.com/cgi-bin/query?pg=q&what=news&fmt=.&q=%2Bcgi-bin+%2Bperl.exe";
        $string =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge;

    Encoding is a bit harder, because you can't just blindly change all the
    non-alphanumunder character (`\W') into their hex escapes. It's
    important that characters with special meaning like `/' and `?' *not* be
    translated. Probably the easiest way to get this right is to avoid
    reinventing the wheel and just use the URI::Escape module, which is part
    of the libwww-perl package (LWP) available from CPAN.

-- 
    In general, they do what you want, unless you want consistency.
            --Larry Wall in the perl man page


------------------------------

Date: 25 Feb 1999 16:33:00 GMT
From: "Matthew Wagley" <gpcu.mwagley@gcnet.com>
Subject: file and directories
Message-Id: <01be60dc$9213df00$0200005a@training>

I know how to open a file in the same directory as I am running a perl
script, but, what if I want to open a file on a different drive or
directory or write to it?

example.

open(PROXYLOG,"c:\proxy\logs\$logproxy")

Thanks in advance for your help.

Matthew Wagley


------------------------------

Date: 25 Feb 1999 18:11:01 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: file and directories
Message-Id: <7b43nl$7ev$1@info.uah.edu>

In article <01be60dc$9213df00$0200005a@training>,
	"Matthew Wagley" <gpcu.mwagley@gcnet.com> writes:
: open(PROXYLOG,"c:\proxy\logs\$logproxy")

Please read Section 5 of the Perl FAQ, paying particular attention
when you read this question:

    Why can't I use ""C:\temp\foo"" in DOS paths?  [Why] doesn't
    `C:\temp\foo.exe` work?

Greg
-- 
When Zarathustra had spoken these words, he again looked at the
people, and was silent. "There they stand," said he to his heart;
"there they laugh: they do not understand me; I am not the mouth for
these ears."  -- Nietzsche


------------------------------

Date: Mon, 22 Feb 1999 01:35:52 GMT
From: squid@fish.net
Subject: Re: File Upload via HTTP progress indicator
Message-Id: <36d0b452.12306098@news.earthlink.net>

Shall Do...It's lookin' like a java or javascript solution is the
answer from my research



------------------------------

Date: 25 Feb 1999 23:18:08 GMT
From: "Douglas K. O'Leary" <dkoleary@tako.wwa.com>
Subject: File::stat->mode?
Message-Id: <7b4lng$fh6$1@hirame.wwa.com>

Hi;

I'm trying to get the modes off of directories in an attempt
to determine which directories are world r/w/x.  I'm getting
some really squirelly results and I'm hoping someone can help.

The snippet of code below looks at the directories under
/home, which look like the following:

drwxr-xr-x   2 root       root          1024 Feb  3  1998 TT_DB/
drwxr-xr-x   7 autosys    sysadmin      1024 Feb  9 14:42 autosys/
drwxr-xr-x   2 dcs        users         1024 Jan 12  1998 dcs/
drwxr-xr-x   2 root       root          8192 Jun 10  1996 lost+found/
drwxr-xr-x   2 pdmsys     pdmsys        1024 Apr 10  1998 pdmsys/
drwxr-xr-x   2 #qmaster   users         1024 May 11  1998 qmaster/
drwxr-xr-x   6 #sybase    sybase        1024 Oct  6 17:44 sybase/
drwxr-xr-x   2 root       sys             24 Jan 18  1998 test/
drwxr-xr-x   4 training   users         1024 Feb 20  1998 training/
drwxrwxrwx  10 tsdol      sysadmin      1024 Feb 25 10:21 tsdol/
drwxr-xr-x   3 #tsdxc     sysadmin      1024 Feb 26  1998 tsdxc/
drwxr-xr-x   2 tsecj      sysadmin        24 Feb 15 10:58 tsecj/
drwxr-xr-x   2 tsjlc      sysadmin      1024 Oct  6 17:44 tsjlc/
drwxr-xr-x   4 #tsjwp     users         1024 Oct  6 17:44 tsjwp/
drwxr-xr-x   6 tsmxs      sysadmin      1024 Jan 27 13:42 tsmxs/
drwxrwxrwx   4 tspmh      sysadmin      1024 Feb  5 07:57 tspmh/
drwxrwxrwx   2 root       sys           1024 Oct  6 17:44 tsrjl/
drwxr-xr-x   6 #tsrld     users         1024 Mar 30  1998 tsrld/
drwx--x--x  19 tssas      sysadmin      1024 Feb 10 09:36 tssas/
drwxr-xr-x   2 tssoc      users         1024 Oct  6 17:44 tssoc/
drwxr-xr-x   2 tsymp      sysadmin      1024 Apr  9  1998 tstmp/

Notice that three directories have 777 perms.  Those are the ones
that I'm trying to ID.

The snippet of code is as follows:

#!/usr/local/bin/perl

use File::stat;

$Dir = "/home";

opendir (Dir,"$Dir") or die "Can't open $Dir - ($!)";
@files = readdir(Dir);

foreach $file (sort @files)
{  if ( -d "$Dir/$file" && $file ne "." && $file ne "..")
   {  $st = stat ("$Dir/$file");
      if ($st->mode & 0007)
      {  print "$Dir/$file is wide open\n";  }
      else
      {  print "$Dir/$file is not wide open\n"; }
   }
}

when compiled and run, it reports that everything is 
wide open.  I got the mode out of sys/stat.h file; the only
thing I can figure is that I got it wrong; however, the 
line seems fairly self explanatory.

Anyone have any hints?  

Thanks!

Doug O'Leary


-- 
    
--------------------
Douglas K. O'Leary
Senior System Admin
dkoleary@mayspeh.com
dkoleary@wwa.com
--------------------


------------------------------

Date: 25 Feb 1999 16:49:25 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: File::stat->mode?
Message-Id: <36d5e185@csnews>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "Douglas K. O'Leary" <dkoleary@tako.wwa.com> writes:
:      if ($st->mode & 0007)
:      {  print "$Dir/$file is wide open\n";  }
:      else
:      {  print "$Dir/$file is not wide open\n"; }

The logic is wrong.  x&y is true if any bits are shared 
in common.  Perhaps you mean (x&y) == y.

--tom
-- 
    "I think the pod should be the master...."
	    --Larry Wall in <9410072305.AA03994@scalpel.netlabs.com>


------------------------------

Date: Thu, 25 Feb 1999 21:25:50 -0600
From: dkoleary@wwa.com (Doug O'Leary)
Subject: Re: File::stat->mode?
Message-Id: <MPG.113fd0355227c46898968e@news.wwa.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <36d5e185@csnews>, tchrist@mox.perl.com says...
> The logic is wrong.  x&y is true if any bits are shared 
> in common.  Perhaps you mean (x&y) == y.
> 
> 
> 

More to the point, that's what I was looking for.  Although I've been 
programming off and on in a variety of languages for a number years, bit 
math has never been something that came easy for me.  I took the logic 
out of the man page for the File::stat module (which, if memory serves, 
you wrote?).  The example that I tried to emulate said something like 
(forgive me if I'm butchering it, this is from memory):

use File::stat;
$st = stat($file);
if ($st->mode & 0111 && $st->nlink > 1)
{	print "$file is executable and has a whole bunch -o links\n";	}

Off subject, but still important:  Thanks for the time and effort you put 
into your books and posts.  I'm assuming you get paid something for the 
books that you write; however, you more than likely don't for the posts.  
I certainly appreciate your efforts.

Doug O'Leary

-- 
==============
Douglas K. O'Leary
Senior System Admin
dkoleary@wwa.com
doleary@ms.acxiom.com
==============


------------------------------

Date: Mon, 22 Feb 1999 10:12:06 -0600
From: Vivek Singh <singh5@students.uiuc.edu>
Subject: files
Message-Id: <36D181D5.F327430D@students.uiuc.edu>

Hi- I am a total dumber in PERL programming and want to do some really
easy stuff. Hopefully someone can help me out.
MY PROBLEM
I have 200 files, each file has same headings but different length. For
example the there are 4 headings in each file namely A,B,C & D. Now I
want to extract all text from heading B for all files and write them in
ONE output file.
Please let me know if you ever came accross such code and I would be
very pleased to recieve a code that can handle it.
Thank you in advance,

Vivek.



------------------------------

Date: Mon, 22 Feb 1999 21:19:51 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: files
Message-Id: <F7Kr93.ECs@world.std.com>

Vivek Singh <singh5@students.uiuc.edu> writes:

>I have 200 files, each file has same headings but different length. For
>example the there are 4 headings in each file namely A,B,C & D. Now I
>want to extract all text from heading B for all files and write them in
>ONE output file.

What does a header look like and what does the data under a heading
look like. Do you want the output to be sequential (all the data under
heading B from file 1, then all the data under heading B from file 2,
etc.) or intermixed (line 1 under heading B from file 1, then line 1
from heading B from file 2, etc.)

I think basically what you want would be something that would do this,
(in pseudocode)

for each file
   open the file
   for each line of the file
     if the current line is the header you are searching for
       for each line of the file
         if the line is the start of a new header
            skip the rest of this file, and start on the next one
         otherwise
            print this line
         end if the line is a header
       end for each line
     end if this line is the header you are searching for
   end for each line of the file
end for each file



Converting this to perl would make it look like this:


#for each file
FILE: for my $file (@ARGV) {
#   open the file
    open FILE, $file or die "Can't open $file: $!\n";
#   for each line of the file
    while(<FILE>) {
#     if the current line is the header you are searching for
#
               ## ??? What goes here ???
#
      if(/some-pattern-that-matches-heading-b/) { 
#       for each line of the file
        while(<FILE>) {
#         if the line is the start of a new header
#
               ## ??? What goes here ???
#
          if(/some-pattern-that-matches-heading-c/) {
#            skip the rest of this file, and start on the next one
             next FILE;
#         otherwise
          }
          else {
#            print this line
             print;
#         end if the line is a header
          }
#       end for each line
        }
#     end if this line is the header you are searching for
      }
#   end for each line of the file
    }
#end for each file
}


So just figure out how to tell the difference between a header and a
non-header, and fill in the blanks.
-- 
Andrew Langmead


------------------------------

Date: 23 Feb 1999 22:07:57 GMT
From: mauro@msan. (Mauro Sanna)
Subject: Finding the week day.
Message-Id: <7av8rt$n3f$1@nslave1.tin.it>

Hi.
Sorry for my bad english, I'm Italian.
I have a great problem.
I can't find the week day of a date.
For example, how can I get the week day of 12/02/1999?
Thanks.

-- 
per rispondere togli <toglimi> dall'indirizzo di posta. 


------------------------------

Date: Tue, 23 Feb 1999 21:47:10 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Finding the week day.
Message-Id: <1dnp736.1as7tc41aqh2f1N@bay1-193.quincy.ziplink.net>

Mauro Sanna <mauro@msan.> wrote:

> I can't find the week day of a date.
> For example, how can I get the week day of 12/02/1999?

I remember seeing this question less than a month ago...
(And less than a month before that.)

Here's the answer I gave, archived by DejaNews:
http://www.dejanews.com/getdoc.xp?AN=431502321

:-)

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

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 4972
**************************************

home help back first fref pref prev next nref lref last post