Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: Leading Spaces and split()

Posted on 2011-08-19 22:01:18 by Deane.Rothenmaier

--===============1119999654==
Content-Type: multipart/alternative;
boundary="_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP 2MBwagreso_"
Content-Language: en-US

--_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP2MBwagre so_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"

Greetings, O Wise Ones...

I'm trying to understand the behavior I'm getting from this code:

#!Perl
############################################################ ###############=
#####
# PROGRAM: array_test1.pl
############################################################ ###############=
#####

use strict;
use warnings;

my $string1 =3D "Windows XP Professional Service Pack 2 (build 2600) Hewlet=
t-Packard";
my $string2 =3D " Windows XP Professional Service Pack 2 (build =
2600) Hewlett-Packard ";

my @ary1;
my @ary2;

@ary1 =3D split( " ", $string1 );

my ($win_type1, $win_ver1, $svc_pack1, $win_build1);

$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];

for ($win_type1) {
/XP/ && do {
$svc_pack1 =3D $ary1[5];
($win_build1 =3D $ary1[7]) =3D~ s{\)}{};
last;
};
}

print "Current Method...\n";
print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";
print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";

my ($win_type2, $win_ver2, $svc_pack2, $win_build2);

for ($string1) {
/XP/ && do {
($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( /\s+/, $=
string1 ))[1, 2, 5, 7];
last;
};
}

$win_build2 =3D~ s{\)}{};

print "Proposed Method...\n";
print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";
print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";



@ary1 =3D split( " ", $string1 );

$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];

for ($win_type1) {
/XP/ && do {
$svc_pack1 =3D $ary1[5];
($win_build1 =3D $ary1[7]) =3D~ s{\)}{};
last;
};
}

print "\nFILE string:\n";
print "Current Method...\n";
print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";
print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";

for ($string2) {
/XP/ && do {
($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( /\s+/, $=
string2 ))[1, 2, 5, 7];
last;
};
}

$win_build2 =3D~ s{\)}{};

print "Proposed Method...\n";
print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";
print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";


############################################################ ###############=
#####
# PROGRAM OUTPUT:
############################################################ ###############=
#####

Current Method...
Type: "XP", Version: "Professional",
Service Pack: "2", Build: "2600"

Proposed Method...
Type: "XP", Version: "Professional",
Service Pack: "2", Build: "2600"

FILE string:
Current Method...
Type: "XP", Version: "Professional",
Service Pack: "2", Build: "2600"

Proposed Method...
Type: "Windows", Version: "XP",
Service Pack: "Pack", Build: "(build"

The red text illustrates the error (if such it be?). My SWAG is that the "n=
othing" between Perl's '^' anchor and the first space in $string2 is what's=
causing the problem. Can someone confirm this? Or provide me with the corr=
ect answer if I'm wrong?

Thanks!

Deane Rothenmaier
Programmer/Analyst - IT-StdCfg
Walgreens Corp.
2 Overlook Point #N51022D
MS 6515
Lincolnshire, IL 60069
224-542-5150

I will make sure that my doomsday device is up to code and properly grounde=
d. - Peter Anspach's list of 100 things to do when one becomes an Evil Over=
lord


--_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP2MBwagre so_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
..MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">Greetings, O Wise Ones&#8230;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">I&#8217;m trying to understand the behavior I&#8217;=
m getting from this code:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">#!Perl<o:p></o:p></p>
<p class=3D"MsoNormal">####################################################=
############################<o:p></o:p></p>
<p class=3D"MsoNormal"># PROGRAM: array_test1.pl<o:p></o:p></p>
<p class=3D"MsoNormal">####################################################=
############################<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">use strict;<o:p></o:p></p>
<p class=3D"MsoNormal">use warnings;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">my $string1 =3D &quot;Windows XP Professional Servic=
e Pack 2 (build 2600) Hewlett-Packard&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal">my $string2 =3D &quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Windows XP Professional Service Pack 2=
(build 2600) Hewlett-Packard &quot;;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">my @ary1;<o:p></o:p></p>
<p class=3D"MsoNormal">my @ary2;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">@ary1 =3D split( &quot; &quot;, $string1 );<o:p></o:=
p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">my ($win_type1, $win_ver1, $svc_pack1, $win_build1);=
<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">$win_type1 =3D $ary1[1];<o:p></o:p></p>
<p class=3D"MsoNormal">$win_ver1 =3D $ary1[2];<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">for ($win_type1) {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $svc_pack1 =3D $ary1[=
5];<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_build1 =3D $ary=
1[7]) =3D~ s{\)}{};<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last;<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; };<o:p></o:p></p>
<p class=3D"MsoNormal">}<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">print &quot;Current Method...\n&quot;;<o:p></o:p></p=
>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type1\&quot;, Version:=
\&quot;$win_ver1\&quot;,\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack1\&quot;, =
Build: \&quot;$win_build1\&quot;\n\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">my ($win_type2, $win_ver2, $svc_pack2, $win_build2);=
<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">for ($string1) {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_type2, $win_ver=
2, $svc_pack2, $win_build2) =3D (split( /\s&#43;/, $string1 ))[1, 2, 5, 7];=
<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last;<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; };<o:p></o:p></p>
<p class=3D"MsoNormal">}<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">$win_build2 =3D~ s{\)}{};<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">print &quot;Proposed Method...\n&quot;;<o:p></o:p></=
p>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type2\&quot;, Version:=
\&quot;$win_ver2\&quot;,\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack2\&quot;, =
Build: \&quot;$win_build2\&quot;\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">@ary1 =3D split( &quot; &quot;, $string1 );<o:p></o:=
p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">$win_type1 =3D $ary1[1];<o:p></o:p></p>
<p class=3D"MsoNormal">$win_ver1 =3D $ary1[2];<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">for ($win_type1) {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $svc_pack1 =3D $ary1[=
5];<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_build1 =3D $ary=
1[7]) =3D~ s{\)}{};<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last;<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; };<o:p></o:p></p>
<p class=3D"MsoNormal">}<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">print &quot;\nFILE string:\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal">print &quot;Current Method...\n&quot;;<o:p></o:p></p=
>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type1\&quot;, Version:=
\&quot;$win_ver1\&quot;,\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack1\&quot;, =
Build: \&quot;$win_build1\&quot;\n\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">for ($string2) {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_type2, $win_ver=
2, $svc_pack2, $win_build2) =3D (split( /\s&#43;/, $string2 ))[1, 2, 5, 7];=
<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last;<o:p></o:p></p>
<p class=3D"MsoNormal">&nbsp;&nbsp; };<o:p></o:p></p>
<p class=3D"MsoNormal">}<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">$win_build2 =3D~ s{\)}{};<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">print &quot;Proposed Method...\n&quot;;<o:p></o:p></=
p>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type2\&quot;, Version:=
\&quot;$win_ver2\&quot;,\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack2\&quot;, =
Build: \&quot;$win_build2\&quot;\n&quot;;<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">####################################################=
############################<o:p></o:p></p>
<p class=3D"MsoNormal"># PROGRAM OUTPUT: <o:p></o:p></p>
<p class=3D"MsoNormal">####################################################=
############################<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Current Method...<o:p></o:p></p>
<p class=3D"MsoNormal">Type: &quot;XP&quot;, Version: &quot;Professional&qu=
ot;,<o:p></o:p></p>
<p class=3D"MsoNormal">Service Pack: &quot;2&quot;, Build: &quot;2600&quot;=
<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Proposed Method...<o:p></o:p></p>
<p class=3D"MsoNormal">Type: &quot;XP&quot;, Version: &quot;Professional&qu=
ot;,<o:p></o:p></p>
<p class=3D"MsoNormal">Service Pack: &quot;2&quot;, Build: &quot;2600&quot;=
<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">FILE string:<o:p></o:p></p>
<p class=3D"MsoNormal">Current Method...<o:p></o:p></p>
<p class=3D"MsoNormal">Type: &quot;XP&quot;, Version: &quot;Professional&qu=
ot;,<o:p></o:p></p>
<p class=3D"MsoNormal">Service Pack: &quot;2&quot;, Build: &quot;2600&quot;=
<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal"><span style=3D"color:red">Proposed Method...<o:p></o=
:p></span></p>
<p class=3D"MsoNormal"><span style=3D"color:red">Type: &quot;Windows&quot;,=
Version: &quot;XP&quot;,<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"color:red">Service Pack: &quot;Pack&q=
uot;, Build: &quot;(build&quot;<o:p></o:p></span></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">The red text illustrates the error (if such it be?).=
My SWAG is that the &#8220;nothing&#8221; between Perl&#8217;s &#8216;^&#8=
217; anchor and the first space in $string2 is what&#8217;s causing the pro=
blem. Can someone confirm this? Or provide me with the correct answer
if I&#8217;m wrong?<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Thanks!<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">Deane Rothenmaier<o:p></o:p></p>
<p class=3D"MsoNormal">Programmer/Analyst &#8211; IT-StdCfg<o:p></o:p></p>
<p class=3D"MsoNormal">Walgreens Corp.<o:p></o:p></p>
<p class=3D"MsoNormal">2 Overlook Point #N51022D<o:p></o:p></p>
<p class=3D"MsoNormal">MS 6515<o:p></o:p></p>
<p class=3D"MsoNormal">Lincolnshire, IL 60069<o:p></o:p></p>
<p class=3D"MsoNormal">224-542-5150<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
<p class=3D"MsoNormal">I will make sure that my doomsday device is up to co=
de and properly grounded. &#8211; Peter Anspach&#8217;s list of 100 things =
to do when one becomes an Evil Overlord<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>

--_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP2MBwagre so_--


--===============1119999654==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1119999654==--

Report this message

#2: Re: Leading Spaces and split()

Posted on 2011-08-20 00:45:00 by Bill Luebkert

On 8/19/2011 1:01 PM, Rothenmaier, Deane C. wrote:
> Greetings, O Wise Ones=85
>
> I=92m trying to understand the behavior I=92m getting from this code:
....
> The red text illustrates the error (if such it be?). My SWAG is that the =
=93nothing=94 between Perl=92s =91^=92 anchor and the first space in $strin=
g2 is what=92s causing the problem. Can someone confirm this? Or provide me=
with the correct answer if I=92m wrong?

perlfunc under split:
As a special case, specifying a PATTERN of space (' ') will sp=
lit on
white space just as "split" with no arguments does. Thus,
"split(' ')" can be used to emulate awk's default behavior, wh=
ereas
"split(/ /)" will give you as many null initial fields as ther=
e are
leading spaces. A "split" on "/\s+/" is like a "split(' ')" ex=
cept
that any leading whitespace produces a null first field. A "sp=
lit"
with no arguments really does a "split(' ', $_)" internally.

# My version:

use strict;
use warnings;
my $string1 =3D
'Windows XP Professional Service Pack 2 (build 2600) Hewlett-Packard';

my @ary1 =3D split ' ', $string1;
my ($win_type1, $win_ver1, $svc_pack1, $win_build1);
$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];
if ($win_type1 =3D~ /XP/) {
$svc_pack1 =3D $ary1[5];
($win_build1 =3D $ary1[7]) =3D~ s/\)//;
}

print "Current Method...\n";
print "Type: '$win_type1', Version: "$win_ver1',\n";
print "Service Pack: '$svc_pack1', Build: '$win_build1'\n\n";

if ($string1 =3D~ /XP/) {
my ($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D
(split /\s+/, $string1)[1, 2, 5, 7];
$win_build2 =3D~ s/\)//;
print "Proposed Method...\n";
print "Type: '$win_type2', Version: '$win_ver2',\n";
print "Service Pack: '$svc_pack2', Build: '$win_build2'\n";
}

@ary1 =3D split ' ', $string1;
$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];
if ($win_type1 =3D~ /XP/) {
$svc_pack1 =3D $ary1[5];
($win_build1 =3D $ary1[7]) =3D~ s{\)}{};
}

print "\nFILE string:\n";
print "Current Method...\n";
print "Type: '$win_type1', Version: '$win_ver1',\n";
print "Service Pack: '$svc_pack1', Build: '$win_build1'\n\n";

my $string2 =3D
" Windows XP Professional Service Pack 2 (build 2600) Hewlett-Packa=
rd ";

if ($string2 =3D~ /XP/) {
$string2 =3D~ s/^\s*//; # I would either use ' ' split or add this line
my ($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D
(split /\s+/, $string2)[1, 2, 5, 7];
$win_build2 =3D~ s/\)//;
print "Proposed Method...\n";
print "Type: '$win_type2', Version: '$win_ver2',\n";
print "Service Pack: '$svc_pack2', Build: '$win_build2'\n";
}

__END__

Current Method...
Type: 'XP', Version: 'Professional',
Service Pack: '2', Build: '2600'

Proposed Method...
Type: 'XP', Version: 'Professional',
Service Pack: '2', Build: '2600'

FILE string:
Current Method...
Type: 'XP', Version: 'Professional',
Service Pack: '2', Build: '2600'

Proposed Method...
Type: 'XP', Version: 'Professional',
Service Pack: '2', Build: '2600'
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#3: Re: Leading Spaces and split()

Posted on 2011-08-20 03:48:53 by Ken Slater

--===============1775864997==
Content-Type: multipart/alternative; boundary=000e0cd3e81265255904aae60c75

--000e0cd3e81265255904aae60c75
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

On Fri, Aug 19, 2011 at 4:01 PM, Rothenmaier, Deane C. <
deane.rothenmaier@walgreens.com> wrote:

> Greetings, O Wise Ones=85****
>
> ** **
>
> I=92m trying to understand the behavior I=92m getting from this code:****
>
> ** **
>
> #!Perl****
>
>
> ############################################################ #############=
#######
> ****
>
> # PROGRAM: array_test1.pl****
>
>
> ############################################################ #############=
#######
> ****
>
> ** **
>
> use strict;****
>
> use warnings;****
>
> ** **
>
> my $string1 =3D "Windows XP Professional Service Pack 2 (build 2600)
> Hewlett-Packard";****
>
> my $string2 =3D " Windows XP Professional Service Pack 2 (buil=
d
> 2600) Hewlett-Packard ";****
>
> ** **
>
> my @ary1;****
>
> my @ary2;****
>
> ** **
>
> @ary1 =3D split( " ", $string1 );****
>
> ** **
>
> my ($win_type1, $win_ver1, $svc_pack1, $win_build1);****
>
> ** **
>
> $win_type1 =3D $ary1[1];****
>
> $win_ver1 =3D $ary1[2];****
>
> ** **
>
> for ($win_type1) {****
>
> /XP/ && do {****
>
> $svc_pack1 =3D $ary1[5];****
>
> ($win_build1 =3D $ary1[7]) =3D~ s{\)}{};****
>
> last;****
>
> };****
>
> }****
>
> ** **
>
> print "Current Method...\n";****
>
> print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";****
>
> print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";****
>
> ** **
>
> my ($win_type2, $win_ver2, $svc_pack2, $win_build2);****
>
> ** **
>
> for ($string1) {****
>
> /XP/ && do {****
>
> ($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( /\s+/,
> $string1 ))[1, 2, 5, 7];****
>
> last;****
>
> };****
>
> }****
>
> ** **
>
> $win_build2 =3D~ s{\)}{};****
>
> ** **
>
> print "Proposed Method...\n";****
>
> print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";****
>
> print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";****
>
> ** **
>
> ** **
>
> ** **
>
> @ary1 =3D split( " ", $string1 );****
>
> ** **
>
> $win_type1 =3D $ary1[1];****
>
> $win_ver1 =3D $ary1[2];****
>
> ** **
>
> for ($win_type1) {****
>
> /XP/ && do {****
>
> $svc_pack1 =3D $ary1[5];****
>
> ($win_build1 =3D $ary1[7]) =3D~ s{\)}{};****
>
> last;****
>
> };****
>
> }****
>
> ** **
>
> print "\nFILE string:\n";****
>
> print "Current Method...\n";****
>
> print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";****
>
> print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";****
>
> ** **
>
> for ($string2) {****
>
> /XP/ && do {****
>
> ($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( /\s+/,
> $string2 ))[1, 2, 5, 7];****
>
> last;****
>
> };****
>
> }****
>
> ** **
>
> $win_build2 =3D~ s{\)}{};****
>
> ** **
>
> print "Proposed Method...\n";****
>
> print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";****
>
> print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";****
>
> ** **
>
> ** **
>
>
> ############################################################ #############=
#######
> ****
>
> # PROGRAM OUTPUT: ****
>
>
> ############################################################ #############=
#######
> ****
>
> ** **
>
> Current Method...****
>
> Type: "XP", Version: "Professional",****
>
> Service Pack: "2", Build: "2600"****
>
> ** **
>
> Proposed Method...****
>
> Type: "XP", Version: "Professional",****
>
> Service Pack: "2", Build: "2600"****
>
> ** **
>
> FILE string:****
>
> Current Method...****
>
> Type: "XP", Version: "Professional",****
>
> Service Pack: "2", Build: "2600"****
>
> ** **
>
> Proposed Method...****
>
> Type: "Windows", Version: "XP",****
>
> Service Pack: "Pack", Build: "(build"****
>
> ** **
>
> The red text illustrates the error (if such it be?). My SWAG is that the
> =93nothing=94 between Perl=92s =91^=92 anchor and the first space in $str=
ing2 is
> what=92s causing the problem. Can someone confirm this? Or provide me wit=
h the
> correct answer if I=92m wrong?****
>
> ** **
>
> Thanks!****
>
> ** **
>
> Deane Rothenmaier****
>
> Programmer/Analyst =96 IT-StdCfg****
>
> Walgreens Corp.****
>
> 2 Overlook Point #N51022D****
>
> MS 6515****
>
> Lincolnshire, IL 60069****
>
> 224-542-5150****
>
> ** **
>
> I will make sure that my doomsday device is up to code and properly
> grounded. =96 Peter Anspach=92s list of 100 things to do when one becomes=
an
> Evil Overlord****
>
>
>
Look at the documentation on the split function (perldoc -f split).
Particularly the section that states:
As a special case, specifying a PATTERN of space (' ') will
split on white space just as "split" with no arguments does.
Thus, "split(' ')" can be used to emulate awk's default
behavior, whereas "split(/ /)" will give you as many initial
null fields (empty string) as there are leading spaces. A
"split" on "/\s+/" is like a "split(' ')" except that any
leading whitespace produces a null first field.

HTH, Ken

--000e0cd3e81265255904aae60c75
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<br><div class=3D"gmail_quote">On Fri, Aug 19, 2011 at 4:01 PM, Rothenmaier=
, Deane C. <span dir=3D"ltr">&lt;<a href=3D"mailto:deane.rothenmaier@walgre=
ens.com">deane.rothenmaier@walgreens.com</a>&gt;</span> wrote:<br><blockquo=
te class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1=
px solid rgb(204, 204, 204); padding-left: 1ex;">






<div link=3D"blue" vlink=3D"purple" lang=3D"EN-US">
<div>
<p class=3D"MsoNormal">Greetings, O Wise Ones=85<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">I=92m trying to understand the behavior I=92m gettin=
g from this code:<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">#!Perl<u></u><u></u></p>
<p class=3D"MsoNormal">####################################################=
############################<u></u><u></u></p>
<p class=3D"MsoNormal"># PROGRAM: <a href=3D"http://array_test1.pl" target=
=3D"_blank">array_test1.pl</a><u></u><u></u></p>
<p class=3D"MsoNormal">####################################################=
############################<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">use strict;<u></u><u></u></p>
<p class=3D"MsoNormal">use warnings;<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">my $string1 =3D &quot;Windows XP Professional Servic=
e Pack 2 (build 2600) Hewlett-Packard&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal">my $string2 =3D &quot;          =
=A0 Windows XP Professional Service Pack 2 (build 2600) Hewlett-Packard &qu=
ot;;<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">my @ary1;<u></u><u></u></p>
<p class=3D"MsoNormal">my @ary2;<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">@ary1 =3D split( &quot; &quot;, $string1 );<u></u><u=
></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">my ($win_type1, $win_ver1, $svc_pack1, $win_build1);=
<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">$win_type1 =3D $ary1[1];<u></u><u></u></p>
<p class=3D"MsoNormal">$win_ver1 =3D $ary1[2];<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">for ($win_type1) {<u></u><u></u></p>
<p class=3D"MsoNormal">   /XP/ &amp;&amp; do {<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 $svc_pack1 =3D $ary1[5];<u></u><u></=
u></p>
<p class=3D"MsoNormal">    =A0 ($win_build1 =3D $ary1[7]) =3D~ s{\)=
}{};<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 last;<u></u><u></u></p>
<p class=3D"MsoNormal">   };<u></u><u></u></p>
<p class=3D"MsoNormal">}<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">print &quot;Current Method...\n&quot;;<u></u><u></u>=
</p>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type1\&quot;, Version:=
\&quot;$win_ver1\&quot;,\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack1\&quot;, =
Build: \&quot;$win_build1\&quot;\n\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">my ($win_type2, $win_ver2, $svc_pack2, $win_build2);=
<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">for ($string1) {<u></u><u></u></p>
<p class=3D"MsoNormal">   /XP/ &amp;&amp; do {<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 ($win_type2, $win_ver2, $svc_pack2, =
$win_build2) =3D (split( /\s+/, $string1 ))[1, 2, 5, 7];<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 last;<u></u><u></u></p>
<p class=3D"MsoNormal">   };<u></u><u></u></p>
<p class=3D"MsoNormal">}<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">$win_build2 =3D~ s{\)}{};<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">print &quot;Proposed Method...\n&quot;;<u></u><u></u=
></p>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type2\&quot;, Version:=
\&quot;$win_ver2\&quot;,\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack2\&quot;, =
Build: \&quot;$win_build2\&quot;\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">@ary1 =3D split( &quot; &quot;, $string1 );<u></u><u=
></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">$win_type1 =3D $ary1[1];<u></u><u></u></p>
<p class=3D"MsoNormal">$win_ver1 =3D $ary1[2];<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">for ($win_type1) {<u></u><u></u></p>
<p class=3D"MsoNormal">   /XP/ &amp;&amp; do {<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 $svc_pack1 =3D $ary1[5];<u></u><u></=
u></p>
<p class=3D"MsoNormal">    =A0 ($win_build1 =3D $ary1[7]) =3D~ s{\)=
}{};<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 last;<u></u><u></u></p>
<p class=3D"MsoNormal">   };<u></u><u></u></p>
<p class=3D"MsoNormal">}<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">print &quot;\nFILE string:\n&quot;;<u></u><u></u></p=
>
<p class=3D"MsoNormal">print &quot;Current Method...\n&quot;;<u></u><u></u>=
</p>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type1\&quot;, Version:=
\&quot;$win_ver1\&quot;,\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack1\&quot;, =
Build: \&quot;$win_build1\&quot;\n\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">for ($string2) {<u></u><u></u></p>
<p class=3D"MsoNormal">   /XP/ &amp;&amp; do {<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 ($win_type2, $win_ver2, $svc_pack2, =
$win_build2) =3D (split( /\s+/, $string2 ))[1, 2, 5, 7];<u></u><u></u></p>
<p class=3D"MsoNormal">    =A0 last;<u></u><u></u></p>
<p class=3D"MsoNormal">   };<u></u><u></u></p>
<p class=3D"MsoNormal">}<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">$win_build2 =3D~ s{\)}{};<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">print &quot;Proposed Method...\n&quot;;<u></u><u></u=
></p>
<p class=3D"MsoNormal">print &quot;Type: \&quot;$win_type2\&quot;, Version:=
\&quot;$win_ver2\&quot;,\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal">print &quot;Service Pack: \&quot;$svc_pack2\&quot;, =
Build: \&quot;$win_build2\&quot;\n&quot;;<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">####################################################=
############################<u></u><u></u></p>
<p class=3D"MsoNormal"># PROGRAM OUTPUT: <u></u><u></u></p>
<p class=3D"MsoNormal">####################################################=
############################<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">Current Method...<u></u><u></u></p>
<p class=3D"MsoNormal">Type: &quot;XP&quot;, Version: &quot;Professional&qu=
ot;,<u></u><u></u></p>
<p class=3D"MsoNormal">Service Pack: &quot;2&quot;, Build: &quot;2600&quot;=
<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">Proposed Method...<u></u><u></u></p>
<p class=3D"MsoNormal">Type: &quot;XP&quot;, Version: &quot;Professional&qu=
ot;,<u></u><u></u></p>
<p class=3D"MsoNormal">Service Pack: &quot;2&quot;, Build: &quot;2600&quot;=
<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">FILE string:<u></u><u></u></p>
<p class=3D"MsoNormal">Current Method...<u></u><u></u></p>
<p class=3D"MsoNormal">Type: &quot;XP&quot;, Version: &quot;Professional&qu=
ot;,<u></u><u></u></p>
<p class=3D"MsoNormal">Service Pack: &quot;2&quot;, Build: &quot;2600&quot;=
<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal"><span style=3D"color: red;">Proposed Method...<u></u=
><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"color: red;">Type: &quot;Windows&quot=
;, Version: &quot;XP&quot;,<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"color: red;">Service Pack: &quot;Pack=
&quot;, Build: &quot;(build&quot;<u></u><u></u></span></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">The red text illustrates the error (if such it be?).=
My SWAG is that the =93nothing=94 between Perl=92s =91^=92 anchor and the =
first space in $string2 is what=92s causing the problem. Can someone confir=
m this? Or provide me with the correct answer
if I=92m wrong?<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">Thanks!<u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">Deane Rothenmaier<u></u><u></u></p>
<p class=3D"MsoNormal">Programmer/Analyst =96 IT-StdCfg<u></u><u></u></p>
<p class=3D"MsoNormal">Walgreens Corp.<u></u><u></u></p>
<p class=3D"MsoNormal">2 Overlook Point #N51022D<u></u><u></u></p>
<p class=3D"MsoNormal">MS 6515<u></u><u></u></p>
<p class=3D"MsoNormal">Lincolnshire, IL 60069<u></u><u></u></p>
<p class=3D"MsoNormal"><a href=3D"tel:224-542-5150" value=3D"+12245425150" =
target=3D"_blank">224-542-5150</a><u></u><u></u></p>
<p class=3D"MsoNormal"><u></u>=A0<u></u></p>
<p class=3D"MsoNormal">I will make sure that my doomsday device is up to co=
de and properly grounded. =96 Peter Anspach=92s list of 100 things to do wh=
en one becomes an Evil Overlord<u></u><u></u></p>
<p class=3D"MsoNormal"><br></p></div></div></blockquote></div><br>Look at t=
he documentation on the split function (perldoc -f split). Particularly the=
section that states:<br>          =A0 As a special cas=
e, specifying a PATTERN of space (&#39; &#39;) will<br>
          =A0 split on white space just as &quot;split&=
quot; with no arguments does.<br>          =A0 Thus, &q=
uot;split(&#39; &#39;)&quot; can be used to emulate awk&#39;s default<br>=
          =A0 behavior, whereas &quot;split(/ /)&quot; =
will give you as many initial<br>
          =A0 null fields (empty string) as there are l=
eading spaces. A<br>          =A0 &quot;split&quot; on =
&quot;/\s+/&quot; is like a &quot;split(&#39; &#39;)&quot; except that any<=
br>          =A0 leading whitespace produces a null fir=
st field.<br>
<br>HTH, Ken<br><br><br>

--000e0cd3e81265255904aae60c75--

--===============1775864997==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1775864997==--

Report this message

#4: Re: Leading Spaces and split()

Posted on 2011-08-22 12:17:01 by Stanislaw Romanski

This is a multi-part message in MIME format.

--===============1845214858==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0038_01CC60C5.65C031A0"

This is a multi-part message in MIME format.

------=_NextPart_000_0038_01CC60C5.65C031A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

Let us assume
my $string2 =3D " Windows XP Professional Service Pack =
2 (build 2600) Hewlett-Packard ";
Then
split( /\s+/, $string2 )
returns the list starting from an empty element, as it matches /\s+/ in =
the beginning of $string2.

You probably like to use
split( ' ', $string2 )
which is the special case for 'split'; it does the matching AFTER =
skipping the leading spaces in $string2.
The returned list will start form 'Windows'.

HTH.

Cheers,

Stanislaw Romanski
----- Original Message -----=20
From: Rothenmaier, Deane C.=20
To: activeperl@listserv.ActiveState.com=20
Sent: Friday, August 19, 2011 10:01 PM
Subject: Leading Spaces and split()


Greetings, O Wise Ones.

=20

I'm trying to understand the behavior I'm getting from this code:

=20

#!Perl

=
############################################################ #############=
#######

# PROGRAM: array_test1.pl

=
############################################################ #############=
#######

=20

use strict;

use warnings;

=20

my $string1 =3D "Windows XP Professional Service Pack 2 (build 2600) =
Hewlett-Packard";

my $string2 =3D " Windows XP Professional Service Pack 2 =
(build 2600) Hewlett-Packard ";

=20

my @ary1;

my @ary2;

=20

@ary1 =3D split( " ", $string1 );

=20

my ($win_type1, $win_ver1, $svc_pack1, $win_build1);

=20

$win_type1 =3D $ary1[1];

$win_ver1 =3D $ary1[2];

=20

for ($win_type1) {

/XP/ && do {

$svc_pack1 =3D $ary1[5];

($win_build1 =3D $ary1[7]) =3D~ s{\)}{};

last;

};

}

=20

print "Current Method...\n";

print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";

print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";

=20

my ($win_type2, $win_ver2, $svc_pack2, $win_build2);

=20

for ($string1) {

/XP/ && do {

($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( =
/\s+/, $string1 ))[1, 2, 5, 7];

last;

};

}

=20

$win_build2 =3D~ s{\)}{};

=20

print "Proposed Method...\n";

print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";

print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";

=20

=20

=20

@ary1 =3D split( " ", $string1 );

=20

$win_type1 =3D $ary1[1];

$win_ver1 =3D $ary1[2];

=20

for ($win_type1) {

/XP/ && do {

$svc_pack1 =3D $ary1[5];

($win_build1 =3D $ary1[7]) =3D~ s{\)}{};

last;

};

}

=20

print "\nFILE string:\n";

print "Current Method...\n";

print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";

print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";

=20

for ($string2) {

/XP/ && do {

($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( =
/\s+/, $string2 ))[1, 2, 5, 7];

last;

};

}

=20

$win_build2 =3D~ s{\)}{};

=20

print "Proposed Method...\n";

print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";

print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";

=20

=20

=
############################################################ #############=
#######

# PROGRAM OUTPUT:=20

=
############################################################ #############=
#######

=20

Current Method...

Type: "XP", Version: "Professional",

Service Pack: "2", Build: "2600"

=20

Proposed Method...

Type: "XP", Version: "Professional",

Service Pack: "2", Build: "2600"

=20

FILE string:

Current Method...

Type: "XP", Version: "Professional",

Service Pack: "2", Build: "2600"

=20

Proposed Method...

Type: "Windows", Version: "XP",

Service Pack: "Pack", Build: "(build"

=20

The red text illustrates the error (if such it be?). My SWAG is that =
the "nothing" between Perl's '^' anchor and the first space in $string2 =
is what's causing the problem. Can someone confirm this? Or provide me =
with the correct answer if I'm wrong?

=20

Thanks!

=20

Deane Rothenmaier

Programmer/Analyst - IT-StdCfg

Walgreens Corp.

2 Overlook Point #N51022D

MS 6515

Lincolnshire, IL 60069

224-542-5150

=20

I will make sure that my doomsday device is up to code and properly =
grounded. - Peter Anspach's list of 100 things to do when one becomes an =
Evil Overlord

=20



------------------------------------------------------------ -------------=
-----


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
------=_NextPart_000_0038_01CC60C5.65C031A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns=3D"http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word" xmlns:m =
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.17102" name=3DGENERATOR>
<STYLE>@font-face {
font-family: Calibri;
}
@page WordSection1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; =
}
P.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: =
"Calibri","sans-serif"
}
LI.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: =
"Calibri","sans-serif"
}
DIV.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: =
"Calibri","sans-serif"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: =
personal-compose
}
..MsoChpDefault {
FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: export-only
}
DIV.WordSection1 {
page: WordSection1
}
</STYLE>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=3DEN-US vLink=3Dpurple link=3Dblue bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>Let us assume</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; my $string2 =
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
Windows&nbsp;&nbsp; XP Professional Service Pack 2 (build 2600) =
Hewlett-Packard=20
";<BR>Then</DIV></FONT>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; split( /\s+/, =
$string2=20
)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>returns&nbsp;the list starting from =
an&nbsp;empty=20
element, as it matches /\s+/ in the beginning of=20
$string2.</FONT></DIV></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>You probably like to use</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; split( ' ', $string2 =

)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>which is the special case for 'split'; =
it=20
</FONT><FONT face=3DArial size=3D2>does the matching AFTER skipping the =
leading=20
spaces in $string2.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The returned list will start form=20
'Windows'.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>HTH.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cheers,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Stanislaw Romanski</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A title=3Ddeane.rothenmaier@walgreens.com=20
href=3D"mailto:deane.rothenmaier@walgreens.com">Rothenmaier, Deane =
C.</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20
title=3Dactiveperl@listserv.ActiveState.com=20
=
href=3D"mailto:activeperl@listserv.ActiveState.com">activepe rl@listserv.A=
ctiveState.com</A>=20
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, August 19, 2011 =
10:01=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Leading Spaces and =
split()</DIV>
<DIV><BR></DIV>
<DIV class=3DWordSection1>
<P class=3DMsoNormal>Greetings, O Wise Ones=85<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>I=92m trying to understand the behavior I=92m =
getting from this=20
code:<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>#!Perl<o:p></o:p></P>
<P=20
=
class=3DMsoNormal>########################################## #############=
#########################<o:p></o:p></P>
<P class=3DMsoNormal># PROGRAM: array_test1.pl<o:p></o:p></P>
<P=20
=
class=3DMsoNormal>########################################## #############=
#########################<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>use strict;<o:p></o:p></P>
<P class=3DMsoNormal>use warnings;<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>my $string1 =3D "Windows XP Professional Service =
Pack 2=20
(build 2600) Hewlett-Packard";<o:p></o:p></P>
<P class=3DMsoNormal>my $string2 =
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Windows XP=20
Professional Service Pack 2 (build 2600) Hewlett-Packard =
";<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>my @ary1;<o:p></o:p></P>
<P class=3DMsoNormal>my @ary2;<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>@ary1 =3D split( " ", $string1 );<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>my ($win_type1, $win_ver1, $svc_pack1,=20
$win_build1);<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>$win_type1 =3D $ary1[1];<o:p></o:p></P>
<P class=3DMsoNormal>$win_ver1 =3D $ary1[2];<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>for ($win_type1) {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $svc_pack1 =
$ary1[5];<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_build1 =3D =
$ary1[7]) =3D~=20
s{\)}{};<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
last;<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; };<o:p></o:p></P>
<P class=3DMsoNormal>}<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>print "Current Method...\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Type: \"$win_type1\", Version:=20
\"$win_ver1\",\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Service Pack: \"$svc_pack1\", Build:=20
\"$win_build1\"\n\n";<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>my ($win_type2, $win_ver2, $svc_pack2,=20
$win_build2);<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>for ($string1) {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_type2, =
$win_ver2,=20
$svc_pack2, $win_build2) =3D (split( /\s+/, $string1 ))[1, 2, 5,=20
7];<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
last;<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; };<o:p></o:p></P>
<P class=3DMsoNormal>}<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>$win_build2 =3D~ s{\)}{};<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>print "Proposed Method...\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Type: \"$win_type2\", Version:=20
\"$win_ver2\",\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Service Pack: \"$svc_pack2\", Build:=20
\"$win_build2\"\n";<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>@ary1 =3D split( " ", $string1 );<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>$win_type1 =3D $ary1[1];<o:p></o:p></P>
<P class=3DMsoNormal>$win_ver1 =3D $ary1[2];<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>for ($win_type1) {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $svc_pack1 =
$ary1[5];<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_build1 =3D =
$ary1[7]) =3D~=20
s{\)}{};<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
last;<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; };<o:p></o:p></P>
<P class=3DMsoNormal>}<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>print "\nFILE string:\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Current Method...\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Type: \"$win_type1\", Version:=20
\"$win_ver1\",\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Service Pack: \"$svc_pack1\", Build:=20
\"$win_build1\"\n\n";<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>for ($string2) {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; /XP/ &amp;&amp; do {<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($win_type2, =
$win_ver2,=20
$svc_pack2, $win_build2) =3D (split( /\s+/, $string2 ))[1, 2, 5,=20
7];<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
last;<o:p></o:p></P>
<P class=3DMsoNormal>&nbsp;&nbsp; };<o:p></o:p></P>
<P class=3DMsoNormal>}<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>$win_build2 =3D~ s{\)}{};<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>print "Proposed Method...\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Type: \"$win_type2\", Version:=20
\"$win_ver2\",\n";<o:p></o:p></P>
<P class=3DMsoNormal>print "Service Pack: \"$svc_pack2\", Build:=20
\"$win_build2\"\n";<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P=20
=
class=3DMsoNormal>########################################## #############=
#########################<o:p></o:p></P>
<P class=3DMsoNormal># PROGRAM OUTPUT: <o:p></o:p></P>
<P=20
=
class=3DMsoNormal>########################################## #############=
#########################<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>Current Method...<o:p></o:p></P>
<P class=3DMsoNormal>Type: "XP", Version: =
"Professional",<o:p></o:p></P>
<P class=3DMsoNormal>Service Pack: "2", Build: "2600"<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>Proposed Method...<o:p></o:p></P>
<P class=3DMsoNormal>Type: "XP", Version: =
"Professional",<o:p></o:p></P>
<P class=3DMsoNormal>Service Pack: "2", Build: "2600"<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>FILE string:<o:p></o:p></P>
<P class=3DMsoNormal>Current Method...<o:p></o:p></P>
<P class=3DMsoNormal>Type: "XP", Version: =
"Professional",<o:p></o:p></P>
<P class=3DMsoNormal>Service Pack: "2", Build: "2600"<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal><SPAN style=3D"COLOR: red">Proposed=20
Method...<o:p></o:p></SPAN></P>
<P class=3DMsoNormal><SPAN style=3D"COLOR: red">Type: "Windows", =
Version:=20
"XP",<o:p></o:p></SPAN></P>
<P class=3DMsoNormal><SPAN style=3D"COLOR: red">Service Pack: "Pack", =
Build:=20
"(build"<o:p></o:p></SPAN></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>The red text illustrates the error (if such it =
be?). My=20
SWAG is that the =93nothing=94 between Perl=92s =91^=92 anchor and the =
first space in=20
$string2 is what=92s causing the problem. Can someone confirm this? Or =
provide=20
me with the correct answer if I=92m wrong?<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>Thanks!<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>Deane Rothenmaier<o:p></o:p></P>
<P class=3DMsoNormal>Programmer/Analyst =96 IT-StdCfg<o:p></o:p></P>
<P class=3DMsoNormal>Walgreens Corp.<o:p></o:p></P>
<P class=3DMsoNormal>2 Overlook Point #N51022D<o:p></o:p></P>
<P class=3DMsoNormal>MS 6515<o:p></o:p></P>
<P class=3DMsoNormal>Lincolnshire, IL 60069<o:p></o:p></P>
<P class=3DMsoNormal>224-542-5150<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P>
<P class=3DMsoNormal>I will make sure that my doomsday device is up to =
code and=20
properly grounded. =96 Peter Anspach=92s list of 100 things to do when =
one becomes=20
an Evil Overlord<o:p></o:p></P>
<P class=3DMsoNormal><o:p>&nbsp;</o:p></P></DIV>
<P>
<HR>

<P></P>_______________________________________________<BR>ActivePerl =
mailing=20
list<BR>ActivePerl@listserv.ActiveState.com<BR>To unsubscribe:=20
=
http://listserv.ActiveState.com/mailman/mysubs</BLOCKQUOTE></BODY></HTML>=


------=_NextPart_000_0038_01CC60C5.65C031A0--


--===============1845214858==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1845214858==--

Report this message

#5: Problem with DB_FIle and Perl 5.12

Posted on 2011-08-24 18:08:37 by Eric Robertson

I have a problem with DB_File and Perl 5.12. I posted a message on the ASPN=
message board but no one there has come back with an
answer so I=92m trying here.

I have some Perl CGI scripts which were developed some time ago using Activ=
ePerl 5.8. When my Mac OS started using 5.10 I considered
upgrading my version of ActivePerl to 5.10 but I couldn't find a couple of =
modules I needed - DBD::CSV and DBD::mysql - so I decided
to continue to use 5.8. These scripts produce BerkeleyDB files using DB_Fil=
e and I found that when I was remotely debugging these
scripts on my virtual host on the Mac these files could be read OK although=
the Mac was using the inbuilt 5.10 because the scripts
contained the normal /usr/bin/perl shebang line.

I've recently upgraded the Mac's OS to Lion and I see that the inbuilt Perl=
version has been changed to 5.12. I now find that I get
an error when I try to read the BerkeleyDB files. I've used the followed co=
de to test the situation and found that 5.12 won't access
files produced by ActivePerl 5.8 and vice versa - the error message is "Can=
't open test.dbm: Inappropriate file type or format".

=A0 =A0 use strict;
=A0 =A0 use Fcntl;
=A0 =A0 use DB_File;
=A0 =A0 my $file =3D 'test.dbm';=A0 =A0 =

my %dbase;
=A0 =A0 my $error;
=A0 =A0 tie (%dbase, 'DB_File', $file, O_RDWR|O_CREAT, 0666, $DB_BTREE) || =
($error=3D1);
=A0 =A0 if ($error) {
=A0 =A0 =A0 print "Can't open $file: $!\n";
=A0 =A0 }
=A0 =A0 $dbase{1} =3D 'one';
=A0 =A0 $dbase{2} =3D 'two';
=A0 =A0 $dbase{3} =3D 'three';
=A0 =A0 untie %dbase;

=A0 =A0 tie (%dbase, 'DB_File', $file, O_RDONLY, 0666, $DB_BTREE) || ($erro=
r=3D1);
=A0 =A0 if ($error) {
=A0 =A0 =A0 print "Can't open $file: $!\n";
=A0 =A0 }

Is the problem something to do with the BerkeleyDB code rather than Perl an=
d how can I correct this? I know I could change the
shebang line in my code when testing on my server but I'd have to remember =
to change this before I uploaded the code to the live
server - which I'm likely to forget!

Eric Robertson

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#6: Re: Problem with DB_FIle and Perl 5.12

Posted on 2011-08-24 19:15:29 by Bill Luebkert

On 8/24/2011 9:08 AM, Eric Robertson wrote:
> I have a problem with DB_File and Perl 5.12. I posted a message on the AS=
PN message board but no one there has come back with an
> answer so I=92m trying here.
>
> I have some Perl CGI scripts which were developed some time ago using Act=
ivePerl 5.8. When my Mac OS started using 5.10 I considered
> upgrading my version of ActivePerl to 5.10 but I couldn't find a couple o=
f modules I needed - DBD::CSV and DBD::mysql - so I decided
> to continue to use 5.8. These scripts produce BerkeleyDB files using DB_F=
ile and I found that when I was remotely debugging these
> scripts on my virtual host on the Mac these files could be read OK althou=
gh the Mac was using the inbuilt 5.10 because the scripts
> contained the normal /usr/bin/perl shebang line.
>
> I've recently upgraded the Mac's OS to Lion and I see that the inbuilt Pe=
rl version has been changed to 5.12. I now find that I get
> an error when I try to read the BerkeleyDB files. I've used the followed =
code to test the situation and found that 5.12 won't access
> files produced by ActivePerl 5.8 and vice versa - the error message is "C=
an't open test.dbm: Inappropriate file type or format".
>
....
>
> Is the problem something to do with the BerkeleyDB code rather than Perl =
and how can I correct this? I know I could change the
> shebang line in my code when testing on my server but I'd have to remembe=
r to change this before I uploaded the code to the live
> server - which I'm likely to forget!

I don't know the exact answer to your problem, but a while back I had a
similar problem and I ended up writing a script that converted the DB
to a flat file (using the old DB module) and then I wrote a script that
converted the flat file back to a DB using the new modules (I believe I
ran the first part at home and then uploaded the flat files to my website
and then ran the conversion to the new DB there). It's at least a
workaround.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message

#7: Re: Problem with DB_FIle and Perl 5.12

Posted on 2011-08-25 11:52:46 by Eric Robertson

On 24 Aug 2011, at 18:15, Bill Luebkert wrote:

> On 8/24/2011 9:08 AM, Eric Robertson wrote:
>> I have a problem with DB_File and Perl 5.12. I posted a message on the A=
SPN message board but no one there has come back with an
>> answer so I=92m trying here.
>> =

>> I have some Perl CGI scripts which were developed some time ago using Ac=
tivePerl 5.8. When my Mac OS started using 5.10 I considered
>> upgrading my version of ActivePerl to 5.10 but I couldn't find a couple =
of modules I needed - DBD::CSV and DBD::mysql - so I decided
>> to continue to use 5.8. These scripts produce BerkeleyDB files using DB_=
File and I found that when I was remotely debugging these
>> scripts on my virtual host on the Mac these files could be read OK altho=
ugh the Mac was using the inbuilt 5.10 because the scripts
>> contained the normal /usr/bin/perl shebang line.
>> =

>> I've recently upgraded the Mac's OS to Lion and I see that the inbuilt P=
erl version has been changed to 5.12. I now find that I get
>> an error when I try to read the BerkeleyDB files. I've used the followed=
code to test the situation and found that 5.12 won't access
>> files produced by ActivePerl 5.8 and vice versa - the error message is "=
Can't open test.dbm: Inappropriate file type or format".
>> =

> ...
>> =

>> Is the problem something to do with the BerkeleyDB code rather than Perl=
and how can I correct this? I know I could change the
>> shebang line in my code when testing on my server but I'd have to rememb=
er to change this before I uploaded the code to the live
>> server - which I'm likely to forget!
> =

> I don't know the exact answer to your problem, but a while back I had a
> similar problem and I ended up writing a script that converted the DB
> to a flat file (using the old DB module) and then I wrote a script that
> converted the flat file back to a DB using the new modules (I believe I
> ran the first part at home and then uploaded the flat files to my website
> and then ran the conversion to the new DB there). It's at least a
> workaround.

Thanks for that workaround. The only copy of my scripts and files are in my=
virtual host. I'd need a script running locally under 5.8 that read the =

DB files and dumped them using, say, Storable and then another script runni=
ng under 5.12 that read the dumps and produced 5.12 compatible =

DB files. =


These DB files would work OK when I was debugging them from my virtual host=
as the shebang would ensure that 5.12 was being used but if I was =

trying to test them locally from Komodo I'd have to change my default setti=
ng for Perl to the 5.12 location. That's certainly a possibility. =


It would be grand if there's a way in Komodo to determine which version of =
Perl to use on a script by script basis.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Report this message