[30650] in Perl-Users-Digest
Perl-Users Digest, Issue: 1895 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 2 09:14:18 2008
Date: Thu, 2 Oct 2008 06:14:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 2 Oct 2008 Volume: 11 Number: 1895
Today's topics:
Re: Regular express for <p>, <ul> and <ol> tags sln@netherlands.com
sysopen - die only if EBUSY? <tch@nospam.wpkg.org>
Re: sysopen - die only if EBUSY? <peter@makholm.net>
Re: sysopen - die only if EBUSY? <tch@nospam.wpkg.org>
Re: What does m@ stand for in the following regular exp QoS@domain.invalid
Re: yaku perl <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 02 Oct 2008 10:14:02 GMT
From: sln@netherlands.com
Subject: Re: Regular express for <p>, <ul> and <ol> tags
Message-Id: <ed69e49kcs0i1ihmsbc9i12ove994501lk@4ax.com>
On Mon, 25 Aug 2008 06:12:06 -0700 (PDT), Shahid <mirzashahidmahmood@gmail.com> wrote:
>Hi,
>I am parsing an .HTML file that contains following example code:
<div>
<p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left"><span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Normal Text Arial 12
Black before bullets.</span></p>
<ul>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">Bullet1: If you want to convert bitmap
images Single Line.</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">Bullet2: D you want to convert </span>
<span style="font-weight:bold;font-size:13pt;font-family:'Times
New Roman';color:#ff0000" xml:lang="en-US" lang="en-US">Times New
Roman Bold Red 13</span><span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US"> like BMP, JPG?</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet3 bold:</span>
<span style="font-size:12pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US"> If you want to convert bitmap images like BMP, JPG</span>
</li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet4 bold 14: </span>
<span style="font-size:14pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US">If you want to convert bitmap images like BMP, JPG 2
lines.</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">Bullet4
bold 14 all Red: </span><span style="font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">If you
want to convert bitmap images like BMP, JPG.</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet4 bold 14 Black: </span>
<span style="font-size:14pt;font-family:'Arial';color:#0000ff"
xml:lang="en-US" lang="en-US">Blue If you want to convert bitmap. </span>
<span style="font-size:16pt;font-family:'Arial';color:#008000"
xml:lang="en-US" lang="en-US">Green 16 images like BMP, JPG.</span>
</li>
</ul>
<p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left"><span style="font-size:14pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">Normal
Text Red Arial 14 after bullets.</span></p>
<p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left;margin-left:0.2500in">
<span style="font-weight:bold;font-size:14pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US"> </span></p>
<p dir="ltr" style="text-align:left"></p>
<p></p>
</div>
>I am trying to parse all the <p>, <ol> and <ul> tags but couldn't
>succeed yet.
>I am trying following Regular Expression(RE):
>"(<[pP][^>]*>(.*)</[pP]>)|(<[oO][lL][^>]+>(.*)</[oO][lL]>)|(<[uU][lL]
>[^>]+>(.*)</[uU][lL]>)"
>
>I am using preg_match_all(). Remember I am working in PHP.
>If any one can help me, I will be very grateful to him/her. I need its
>solution urgent.
Couple of solutions. This module shown here is not out yet.
When it is, it can not only get what you need quickly but you can edit
and reconstruct it to a file. Its also a quick way to chop up code source
and can be passed to xml-simple.
Using your source html, here is some sample code and output.
There are three samples separated by ###'s.
sln
############################################################################
# Capture form: 'p', 'ol' or 'ul' tag is buffer: <tag> tag_data </tag>
# Use sequence to reconstruct original source
# ---------------------------------------------
use strict;
use warnings;
use RXParse; # VERSIN 2
my $p = new RXParse();
$p->setMode( 'html' => 1, 'resume_onerror'=> 1 );
my $fname = 'c:\temp\newsgrp.xml';
open my $fh_xml, $fname or die "can't open $fname...";
my %oldh = $p->setHandlers('start' => \&starth, 'end' => \&endh);
sub starth
{
my ($obj, $el, $term, @attr) = @_;
my $buffer = lc($el);
if ($buffer eq 'p' || $buffer eq 'ol' || $buffer eq 'ul')
{
$obj->CaptureOn( $buffer );
$obj->CaptureOn( $buffer."_data", 1 );
}
# optional, call old handler
$oldh{'start'}($obj, $el, $term, @attr );
}
sub endh
{
my ($obj, $el, $term) = @_;
my $buffer = lc($el);
if ($buffer eq 'p' || $buffer eq 'ol' || $buffer eq 'ul')
{
$obj->CaptureOff( $buffer."_data" );
$obj->CaptureOff( $buffer, 1 );
}
# optional, call old handler
$oldh{'end'}($obj, $el, $term );
}
$p->CaptureOn('ALL');
my $parse_ln = "";
$parse_ln = join ('', <$fh_xml>); # join file data
my $parse_errors = $p->parse(\$parse_ln); # or pass in $fh_xml
$p->CaptureOff('ALL');
$p->DumpCaptureBuffs();
close $fh_xml;
print STDERR "Parse errors = $parse_errors\n";
__END__
BUFFER: all
=====================================
index seqence
----- --------
[0] 1 <div>
[1] -2
[2] 5
[3] -6
[4] 9
[5] -10
[6] 13
[7] -14
[8] 17
[9] -18
[10] 21
[11] -22
[12] 25
</div>
BUFFER: p
=====================================
index seqence
----- --------
[0] 2 <p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left">
[1] -3
[2] 4 </p>
[3] 10 <p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left">
[4] -11
[5] 12 </p>
[6] 14 <p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left;margin-left:0.2500in">
[7] -15
[8] 16 </p>
[9] 18 <p dir="ltr" style="text-align:left">
[10] -19
[11] 20 </p>
[12] 22 <p>
[13] -23
[14] 24 </p>
BUFFER: p_data
=====================================
index seqence
----- --------
[0] 3 <span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Normal Text Arial 12
Black before bullets.</span>
[1] 11 <span style="font-size:14pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">Normal
Text Red Arial 14 after bullets.</span>
[2] 15
<span style="font-weight:bold;font-size:14pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US"> </span>
[3] 19 undefined
[4] 23 undefined
BUFFER: ul
=====================================
index seqence
----- --------
[0] 6 <ul>
[1] -7
[2] 8 </ul>
BUFFER: ul_data
=====================================
index seqence
----- --------
[0] 7
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">Bullet1: If you want to convert bitmap
images Single Line.</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">Bullet2: D you want to convert </span>
<span style="font-weight:bold;font-size:13pt;font-family:'Times
New Roman';color:#ff0000" xml:lang="en-US" lang="en-US">Times New
Roman Bold Red 13</span><span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US"> like BMP, JPG?</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet3 bold:</span>
<span style="font-size:12pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US"> If you want to convert bitmap images like BMP, JPG</span>
</li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet4 bold 14: </span>
<span style="font-size:14pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US">If you want to convert bitmap images like BMP, JPG 2
lines.</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">Bullet4
bold 14 all Red: </span><span style="font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">If you
want to convert bitmap images like BMP, JPG.</span></li>
<li class="html_preformatted" dir="ltr" style="text-
align:left"> <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet4 bold 14 Black: </span>
<span style="font-size:14pt;font-family:'Arial';color:#0000ff"
xml:lang="en-US" lang="en-US">Blue If you want to convert bitmap. </span>
<span style="font-size:16pt;font-family:'Arial';color:#008000"
xml:lang="en-US" lang="en-US">Green 16 images like BMP, JPG.</span>
</li>
##############################################################
# Capture form: tag is buffer "<tag> data </tag>"
# Use sequence to reconstruct original source
# ---------------------------------------------
use strict;
use warnings;
use RXParse; # VERSIN 2
my $p = new RXParse();
$p->setMode( 'html' => 1, 'resume_onerror'=> 1 );
my $fname = 'c:\temp\newsgrp.xml';
open my $fh_xml, $fname or die "can't open $fname...";
my %oldh = $p->setHandlers('start' => \&starth, 'end' => \&endh, 'captnotify' => \&cnotify);
my %closetags = ('br'=> '', 'img'=>'', 'meta'=>'', 'link'=> '', 'input'=>'');
sub cnotify
{
my ($obj, $buffer) = @_;
if (exists $closetags{$buffer})
{
$obj->CaptureOff( $buffer );
}
}
sub starth
{
my ($obj, $el, $term, @attr) = @_;
my $buffer = lc($el);
$obj->CaptureOn( $buffer );
# optional, call old handler
$oldh{'start'}($obj, $el, $term, @attr );
}
sub endh
{
my ($obj, $el, $term) = @_;
my $buffer = lc($el);
$obj->CaptureOff( $buffer, 1 );
# optional, call old handler
$oldh{'end'}($obj, $el, $term );
}
$p->CaptureOn('ALL');
my $parse_ln = "";
$parse_ln = join ('', <$fh_xml>); # join file data
my $parse_errors = $p->parse(\$parse_ln); # or pass in $fh_xml
$p->CaptureOff('ALL');
$p->DumpCaptureBuffs();
close $fh_xml;
print STDERR "Parse errors = $parse_errors\n";
__END__
BUFFER: all
=====================================
index seqence
----- --------
[0] 1
[1] -2
[2] 59 undefined
BUFFER: ul
=====================================
index seqence
----- --------
[0] 7 <ul>
[1] -8
[2] 11
[3] -12
[4] 19
[5] -20
[6] 25
[7] -26
[8] 31
[9] -32
[10] 37
[11] -38
[12] 45
</ul>
BUFFER: div
=====================================
index seqence
----- --------
[0] 2 <div>
[1] -3
[2] 6
[3] -7
[4] 46
[5] -47
[6] 50
[7] -51
[8] 54
[9] -55
[10] 56
[11] -57
[12] 58
</div>
BUFFER: p
=====================================
index seqence
----- --------
[0] 3 <p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left">
[1] -4
[2] 5 </p>
[3] 47 <p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left">
[4] -48
[5] 49 </p>
[6] 51 <p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left;margin-left:0.2500in">
[7] -52
[8] 53 </p>
[9] 55 <p dir="ltr" style="text-align:left"></p>
[10] 57 <p></p>
BUFFER: li
=====================================
index seqence
----- --------
[0] 8 <li class="html_preformatted" dir="ltr" style="text-
align:left">
[1] -9
[2] 10 </li>
[3] 12 <li class="html_preformatted" dir="ltr" style="text-
align:left">
[4] -13
[5] 14
[6] -15
[7] 16 undefined
[8] -17
[9] 18 </li>
[10] 20 <li class="html_preformatted" dir="ltr" style="text-
align:left">
[11] -21
[12] 22
[13] -23
[14] 24
</li>
[15] 26 <li class="html_preformatted" dir="ltr" style="text-
align:left">
[16] -27
[17] 28
[18] -29
[19] 30 </li>
[20] 32 <li class="html_preformatted" dir="ltr" style="text-
align:left">
[21] -33
[22] 34 undefined
[23] -35
[24] 36 </li>
[25] 38 <li class="html_preformatted" dir="ltr" style="text-
align:left">
[26] -39
[27] 40
[28] -41
[29] 42
[30] -43
[31] 44
</li>
BUFFER: span
=====================================
index seqence
----- --------
[0] 4 <span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Normal Text Arial 12
Black before bullets.</span>
[1] 9 <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">Bullet1: If you want to convert bitmap
images Single Line.</span>
[2] 13 <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">Bullet2: D you want to convert </span>
[3] 15 <span style="font-weight:bold;font-size:13pt;font-family:'Times
New Roman';color:#ff0000" xml:lang="en-US" lang="en-US">Times New
Roman Bold Red 13</span>
[4] 17 <span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US"> like BMP, JPG?</span>
[5] 21 <span style="font-weight:bold;font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet3 bold:</span>
[6] 23 <span style="font-size:12pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US"> If you want to convert bitmap images like BMP, JPG</span>
[7] 27 <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet4 bold 14: </span>
[8] 29 <span style="font-size:14pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US">If you want to convert bitmap images like BMP, JPG 2
lines.</span>
[9] 33 <span style="font-weight:bold;font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">Bullet4
bold 14 all Red: </span>
[10] 35 <span style="font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">If you
want to convert bitmap images like BMP, JPG.</span>
[11] 39 <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">Bullet4 bold 14 Black: </span>
[12] 41 <span style="font-size:14pt;font-family:'Arial';color:#0000ff"
xml:lang="en-US" lang="en-US">Blue If you want to convert bitmap. </span>
[13] 43 <span style="font-size:16pt;font-family:'Arial';color:#008000"
xml:lang="en-US" lang="en-US">Green 16 images like BMP, JPG.</span>
[14] 48 <span style="font-size:14pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">Normal
Text Red Arial 14 after bullets.</span>
[15] 52 <span style="font-weight:bold;font-size:14pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US"> </span>
##############################################################
# Capture form: data is buffer <tag> "data" </tag>
# Use sequence to reconstruct original source
# ---------------------------------------------
use strict;
use warnings;
use RXParse; # VERSIN 2
my $p = new RXParse();
$p->setMode( 'html' => 1, 'resume_onerror'=> 1 );
my $fname = 'c:\temp\newsgrp.xml';
open my $fh_xml, $fname or die "can't open $fname...";
my %oldh = $p->setHandlers('start' => \&starth, 'end' => \&endh);
my %closetags = ('br'=> '', 'img'=>'', 'meta'=>'', 'link'=> '', 'input'=>'');
sub starth
{
my ($obj, $el, $term, @attr) = @_;
my $buffer = lc($el);
if (!exists $closetags{$buffer})
{
$obj->CaptureOn( $buffer, 1 );
}
# optional, call old handler
$oldh{'start'}($obj, $el, $term, @attr );
}
sub endh
{
my ($obj, $el, $term) = @_;
my $buffer = lc($el);
$obj->CaptureOff( $buffer );
# optional, call old handler
$oldh{'end'}($obj, $el, $term );
}
$p->CaptureOn('ALL');
my $parse_ln = "";
$parse_ln = join ('', <$fh_xml>); # join file data
my $parse_errors = $p->parse(\$parse_ln); # or pass in $fh_xml
$p->CaptureOff('ALL');
$p->DumpCaptureBuffs();
close $fh_xml;
print STDERR "Parse errors = $parse_errors\n";
__END__
BUFFER: all
=====================================
index seqence
----- --------
[0] 1 <div>
[1] -2
[2] 59 </div>
BUFFER: ul
=====================================
index seqence
----- --------
[0] 7
<li class="html_preformatted" dir="ltr" style="text-
align:left">
[1] -8
[2] 11 </li>
<li class="html_preformatted" dir="ltr" style="text-
align:left">
[3] -12
[4] 19 </li>
<li class="html_preformatted" dir="ltr" style="text-
align:left">
[5] -20
[6] 25 </li>
<li class="html_preformatted" dir="ltr" style="text-
align:left">
[7] -26
[8] 31 </li>
<li class="html_preformatted" dir="ltr" style="text-
align:left">
[9] -32
[10] 37 </li>
<li class="html_preformatted" dir="ltr" style="text-
align:left">
[11] -38
[12] 45 </li>
BUFFER: div
=====================================
index seqence
----- --------
[0] 2
<p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left">
[1] -3
[2] 6 </p>
<ul>
[3] -7
[4] 46 </ul>
<p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left">
[5] -47
[6] 50 </p>
<p class="html_preformatted" awml:style="HTML Preformatted"
dir="ltr" style="text-align:left;margin-left:0.2500in">
[7] -51
[8] 54 </p>
<p dir="ltr" style="text-align:left">
[9] -55
[10] 56 </p>
<p>
[11] -57
[12] 58 </p>
BUFFER: p
=====================================
index seqence
----- --------
[0] 3 <span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">
[1] -4
[2] 5 </span>
[3] 47 <span style="font-size:14pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">
[4] -48
[5] 49 </span>
[6] 51
<span style="font-weight:bold;font-size:14pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">
[7] -52
[8] 53 </span>
[9] 55 undefined
[10] 57 undefined
BUFFER: li
=====================================
index seqence
----- --------
[0] 8 <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">
[1] -9
[2] 10 </span>
[3] 12 <span style="font-size:12pt;font-family:'Arial'"
xml:lang="en-US" lang="en-US">
[4] -13
[5] 14 </span>
<span style="font-weight:bold;font-size:13pt;font-family:'Times
New Roman';color:#ff0000" xml:lang="en-US" lang="en-US">
[6] -15
[7] 16 </span><span style="font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">
[8] -17
[9] 18 </span>
[10] 20 <span style="font-weight:bold;font-size:12pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">
[11] -21
[12] 22 </span>
<span style="font-size:12pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US">
[13] -23
[14] 24 </span>
[15] 26 <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">
[16] -27
[17] 28 </span>
<span style="font-size:14pt;font-family:'Arial'" xml:lang="en-US"
lang="en-US">
[18] -29
[19] 30 </span>
[20] 32 <span style="font-weight:bold;font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">
[21] -33
[22] 34 </span><span style="font-size:16pt;font-
family:'Arial';color:#ff0000" xml:lang="en-US" lang="en-US">
[23] -35
[24] 36 </span>
[25] 38 <span style="font-weight:bold;font-size:14pt;font-
family:'Arial'" xml:lang="en-US" lang="en-US">
[26] -39
[27] 40 </span>
<span style="font-size:14pt;font-family:'Arial';color:#0000ff"
xml:lang="en-US" lang="en-US">
[28] -41
[29] 42 </span>
<span style="font-size:16pt;font-family:'Arial';color:#008000"
xml:lang="en-US" lang="en-US">
[30] -43
[31] 44 </span>
BUFFER: span
=====================================
index seqence
----- --------
[0] 4 Normal Text Arial 12
Black before bullets.
[1] 9 Bullet1: If you want to convert bitmap
images Single Line.
[2] 13 Bullet2: D you want to convert
[3] 15 Times New
Roman Bold Red 13
[4] 17 like BMP, JPG?
[5] 21 Bullet3 bold:
[6] 23 If you want to convert bitmap images like BMP, JPG
[7] 27 Bullet4 bold 14:
[8] 29 If you want to convert bitmap images like BMP, JPG 2
lines.
[9] 33 Bullet4
bold 14 all Red:
[10] 35 If you
want to convert bitmap images like BMP, JPG.
[11] 39 Bullet4 bold 14 Black:
[12] 41 Blue If you want to convert bitmap.
[13] 43 Green 16 images like BMP, JPG.
[14] 48 Normal
Text Red Arial 14 after bullets.
[15] 52
------------------------------
Date: Thu, 02 Oct 2008 14:49:52 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: sysopen - die only if EBUSY?
Message-Id: <gc2g1g$4e6$1@online.de>
I want to check if a given block device is already used by the system
(i.e. device is mounted, used for swap, part of a RAID array etc.).
In short, it can be done with:
use Fcntl qw(O_RDONLY O_EXCL);
my $path = "/dev/sda";
sysopen(FH, $path, O_RDONLY | O_EXCL) or die $!;
If /dev/sda is really used, the script will die with
"Device or resource busy" error message (depending on locales).
Low level, it can be seen as:
open("/dev/sda", O_RDONLY|O_EXCL|O_LARGEFILE) = -1 EBUSY (Device or resource busy)
The script will also die if the file does not exist - looking
low level it would be:
open("/dev/blah", O_RDONLY|O_EXCL|O_LARGEFILE) = -1 ENOENT (No such file or directory)
I want the script to take a specified action depending on
the error (EBUSY, ENOENT, etc.).
How can I read these values?
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Thu, 02 Oct 2008 14:57:15 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: sysopen - die only if EBUSY?
Message-Id: <874p3vyx1w.fsf@hacking.dk>
Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
> I want the script to take a specified action depending on
> the error (EBUSY, ENOENT, etc.).
> How can I read these values?
The numeric value of $! would corrospond to the actual error code.
If you 'use Errno;' you will have a magic %! which can be easier to
use. If the error was EBUSY then $!{EBUSY} would be true, if the error
wwas ENOENT $!{[ENOENT} is true, and so on.
Read 'perldoc Errno'
//Makholm
------------------------------
Date: Thu, 02 Oct 2008 15:02:51 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: Re: sysopen - die only if EBUSY?
Message-Id: <gc2gps$2if$1@online.de>
Peter Makholm schrieb:
> Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
>
>> I want the script to take a specified action depending on
>> the error (EBUSY, ENOENT, etc.).
>> How can I read these values?
>
> The numeric value of $! would corrospond to the actual error code.
>
> If you 'use Errno;' you will have a magic %! which can be easier to
> use. If the error was EBUSY then $!{EBUSY} would be true, if the error
> wwas ENOENT $!{[ENOENT} is true, and so on.
>
> Read 'perldoc Errno'
Thanks!
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: 02 Oct 2008 02:17:18 GMT
From: QoS@domain.invalid
Subject: Re: What does m@ stand for in the following regular expression.
Message-Id: <48e42f2e$0$28739$88260bb3@news.teranews.com>
grocery_stocker <cdalten@gmail.com> wrote in message-id: <21d009de-7b8b-47af-b156-099716358217@i76g2000hsf.googlegroups.com>
>
> Given
>
> my ($title) = ($body =~ m@<title>\s*(.*?)\s*</title>@si);
>
>
> What does m@ do in this case?
m = match
@ = marks the beginning and end of the regular expression
------------------------------
Date: Wed, 1 Oct 2008 22:33:57 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: yaku perl
Message-Id: <slrnge8g95.6ar.tadmc@tadmc30.sbcglobal.net>
Tim Greer <tim@burlyhost.com> wrote:
> Maybe they just wanted to post nonsense? :-)
This OP has done this about a dozen times here in the past.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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.
#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 V11 Issue 1895
***************************************