#! /usr/bin/perl -w ## This command is the guts of csh script "bbcextract', and called by it. undef $/; $_ = ; # read in whole file $name = $0; $name =~ s|.*/||; # print("Hallo from $name\n"); #$infile = "$ARGV[1]"; # bbcnewsdaily. Taken care of in calling script. $indir = '/home/steve/mail/IN'; $outnamepat = 'newsXXYYY.html'; $index = 1; if (scalar(@ARGV) > 0) { $indir = $ARGV[0]; shift @ARGV;}; if (scalar(@ARGV) > 0) { $outnamepat = $ARGV[0]; shift @ARGV;}; if (scalar(@ARGV) > 0) { $index = $ARGV[0]; shift @ARGV;}; #print("Hallo2 from $name: '$outnamepat' '$index' \n"); if ($index < 0) { $index = -$index;} if ($index == 0) { print "Index cannot be zero.\n"; exit; }; @emails = split('\nFrom [\w\.]+@', $_); # Loses the word From and only part of name #@emails = split('\nFrom ', $_); # Loses the word From #@emails = split('\nFrom [\w\.]+@[\w\.]+', $_); $n = scalar(@emails); $nn = $n - 1; $ind = $index; # In Alpine, there is a dummy email at top: in the array, but not # meaningful here. #print "Nmb of array slots is $n, Nmb. of real emails is $nn, # index-arg is $ind\n"; #print "n-1 is $nn, index-arg is $ind\n"; if ($nn < $ind) { print "Only $nn real emails in the mail file.\n"; exit; }; # Hidden 1st "msg" is the alpine index file $email = $emails[-$index]; @words = split(/ +/, $email); $date = $words[3] . $words[2]; $fileout = $outnamepat; $fileout =~ s/XXYYY/$date/; $fileout = $indir . '/' . $fileout; #print "Hallo4: $fileout \n"; #exit; if ($email =~ m|) # elsif () {} else { $email =~ s|.*()|$1|is; }; # Deletes everything before opening ) # /s means ignore lines, do multi-line matching $email =~ s|(.*).*|$1\n|is; # /s means ignore lines # Deletes everything after the closing # Now output open(STDOUT, ">$fileout") || print ("Can't open $fileout: $! \n", exit); print $email || print (STDERR "Can't write $fileout: $! \n", exit); __END__ print "Hallo4: $fileout \n"; #print "Hallo4: @words[2 .. 3] \n"; # A: INITS # B: ARG processing $name = $0; $name =~ s|.*/||; $fixpc = ($name eq 'FMT'); while (scalar(@ARGV) > 0) { if ($ARGV[0] =~ m/^-h.*/i) { $hyphen = ! $hyphen; } elsif ($ARGV[0] =~ m/^-?\d/) { $llen = $ARGV[0]; $llen = ($llen < 0 ? -($llen) : $llen ); } elsif ($ARGV[0] =~ m/^-/) { print("Bad flag arg(s): @ARGV\n"); exit; } elsif (scalar(@ARGV) >1 ) { print("Too many args: @ARGV\n"); exit; } else {last;}; shift @ARGV; }; if (-t STDIN) { die "Must have datafile on STDIN"; }; # combine args and/or split words within one arg $myarg = join(',', @ARGV); $myarg =~ s/ /,/g; $myarg =~ s/,+/,/g; @list = split(',', $myarg); #C: READ in file undef $/; $_ = <>; $/ = "\n"; # read in whole file OR open(STDOUT, "| sort -u > $tmp"); open(STDIN, "<$fileXx") || print ("Can't open $fileXx: $! \n"); while (<>) { chop; foreach $url (@urls) { if ($url eq $_) {next Lwhile;}; }; $x = ` webget -nostrip -nofollow -quiet $_ 2>&1 `; $ok = ($x =~ /^HTTP/ && $x =~ /200/); if ($ok) { if ($x =~ /TITLE/i) { }; sub getrank { local ($m, $p, $q) = @_; # assume 3 args passed. local ($rank, $tot); # local vars local $max = 2; .... return ($rank, $tot); # Output array / 2 values. }; sub pp { foreach $g (@_) { print "$g\n";}; }; print "A: @array \n"; # Print contents of an array on one line. print(join("\n", @strs) . "\n\n"); # print contents of an array one per line. foreach $k (keys(%addr)) { print "$k: $addr{$k}\n"; }; $d = sprintf(":%.2d", $min) . ($h < 12 ? 'am' : 'pm') . " $d"; __END__ Can have any old comments here. (Or data)