Unicode, Null Code or Something Else

2013-01-24 Thread Paul Rousseau

Hello Perl forum.
 
I am attempting to parse a file that contains a format I am not familiar with. 
I read in a record and assign it to $string.
 
$string = N o r m a n d v i l l e A d m i n
 
When I dump the string using this code,
 
while ($string =~ /./g)
  {
   print $ and  . ord($) .  length  . length($);
  }

I get
 
  and 0 length 1
N and 78 length 1
  and 0 length 1
o and 111 length 1
  and 0 length 1
r and 114 length 1
  and 0 length 1
m and 109 length 1
  and 0 length 1
a and 97 length 1
  and 0 length 1
n and 110 length 1
  and 0 length 1
d and 100 length 1
  and 0 length 1
v and 118 length 1
  and 0 length 1
i and 105 length 1
  and 0 length 1
l and 108 length 1
  and 0 length 1
l and 108 length 1
  and 0 length 1
e and 101 length 1
  and 0 length 1
A and 65 length 1
  and 0 length 1
d and 100 length 1
  and 0 length 1
m and 109 length 1
  and 0 length 1
i and 105 length 1
  and 0 length 1
n and 110 length 1
  and 0 length 1
 
Can someone answer two questions for me please?
 
1. What format does this represent?
2. What function or library or regexp can I use to convert the string to the 
basic ASCII so that all these null codes go away? (In other words, I want to 
convert $string to NormandvilleAdmin)
 
Thank you
 
Paul Rousseau
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Unicode, Null Code or Something Else

2013-01-24 Thread Paul Rousseau

Thank you Glenn.
 
open(my $file,:encoding(UTF-16), $filename) 
 
This works.
 
Paul

 




Date: Thu, 24 Jan 2013 09:39:49 -0800
From: v+p...@g.nevcal.com
To: perl-win32-users@listserv.ActiveState.com
Subject: Re: Unicode, Null Code or Something Else


On 1/24/2013 9:36 AM, Paul Rousseau wrote:




Hello Perl forum.
 
I am attempting to parse a file that contains a format I am not familiar with. 
I read in a record and assign it to $string.
 
$string = N o r m a n d v i l l e A d m i n
 
When I dump the string using this code,
 
while ($string =~ /./g)
  {
   print $ and  . ord($) .  length  . length($);
  }

I get
 
  and 0 length 1
N and 78 length 1
  and 0 length 1
o and 111 length 1
  and 0 length 1
r and 114 length 1
  and 0 length 1
m and 109 length 1
  and 0 length 1
a and 97 length 1
  and 0 length 1
n and 110 length 1
  and 0 length 1
d and 100 length 1
  and 0 length 1
v and 118 length 1
  and 0 length 1
i and 105 length 1
  and 0 length 1
l and 108 length 1
  and 0 length 1
l and 108 length 1
  and 0 length 1
e and 101 length 1
  and 0 length 1
A and 65 length 1
  and 0 length 1
d and 100 length 1
  and 0 length 1
m and 109 length 1
  and 0 length 1
i and 105 length 1
  and 0 length 1
n and 110 length 1
  and 0 length 1
 
Can someone answer two questions for me please?
 
1. What format does this represent?
2. What function or library or regexp can I use to convert the string to the 
basic ASCII so that all these null codes go away? (In other words, I want to 
convert $string to NormandvilleAdmin)

You should read about UTF-16BE encoding.

___ Perl-Win32-Users mailing list 
Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: 
http://listserv.ActiveState.com/mailman/mysubs  
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: How to Use XML::Parser to Reduce an XML file to what is wanted

2012-11-05 Thread Paul Rousseau
=011-30.PLC.Global.TEMP_BYPASS/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.Time_Set_ons/ItemItem AccessPath= 
Active=-1 ReqDataType=011-30.PLC.Global.Time_Set_Trig/ItemItem 
AccessPath= Active=-1 ReqDataType=011-30.PLC.Global.UL_H2S/ItemItem 
AccessPath= Active=-1 ReqDataType=011-30.PLC.Global.UL_LEL/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.UL_PROCESS/ItemItem AccessPath= 
Active=-1 ReqDataType=011-30.PLC.Global.ACKNOWLEDGE.Alarmed/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ZSO_01_1110.DigitalAnnunciator.AlarmInput/ItemItem
 AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ZSO_01_1110.DigitalAnnunciator.AlarmPosition/ItemItem
 AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ZSO_01_1110.DigitalAnnunciator.ArrayBitOffset/ItemItem
 AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassStart/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassStatus/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassStop/ItemItem AccessPath= 
Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimeSetpoint/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.CalloutPosition/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.ClassCEnable/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.ClassCStatus/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.ClassCTimeSetpoint/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.DebounceTimeSetpoint/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.EnableIn/ItemItem AccessPath= 
Active=-1 ReqDataType=011-30.PLC.Global.ES23_0001.EnableOut/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.InputLatched/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.Latched/ItemItem AccessPath= 
Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.MotorStatusBypass/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.NonLatched/ItemItem AccessPath= 
Active=-1 ReqDataType=011-30.PLC.Global.ES23_0001.RawInput/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.CTL_x.CTL_00/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.ACC/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.DN/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.EN/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.PRE/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.TT/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.CTL_x.CTL_01/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.CTL_x.CTL_02/ItemItem 
AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.BypassTimer.CTL_x.CTL_03/Item/Group/Server/Hostname/Session
Here is the result. ?xml version=1.0?Session
Hostname Remote=0 RemoteHost=\\SCADA
Server Name=Kepware.KEPServerEX.V5 Connected=1 GroupCount=1
Group Name=11-30 Active=-1 ReqUpdateRate=1 TimeBias=-420 
PercentDeadband=0.00 Connected=2 ItemCount=26283 

Item AccessPath= Active=-1 
ReqDataType=011-30.PLC.Global.ES23_0001.Latched/Item 
/Group
/Server
/Hostname
/Session
 Thank you. Paul   From: je...@krynicky.cz
 To: perl-win32-users@listserv.activestate.com
 Date: Thu, 1 Nov 2012 18:20:06 +0100
 Subject: Re: How to Use XML::Parser to Reduce an XML file to what is wanted
 
 From: Paul Rousseau paulrousseau...@hotmail.com
  I have an .xml file that I want to search for specific items, ignoring the 
  remaining items.
  
  I want to be able to maintain the .xml file integrity, so I want to open 
  the original and after finding what I am looking for, dump the results to a 
  second file.
 
  I am thinking I would need logic to do the following.
   
  1. Open the .xml file.
  2. Begin parsing.
  3. If the object is not 'Item', keep it. (This will keep objects such as 
  'Session', 'Server', 'Group')
  4. If the object is 'Item', and it contains the text, '.Latched', keep it.
  5. Otherwise, ignore 'Item'
  6. Open the output file.
  7. Write out all the kept items.
  8. Close both files.
   
  Any help would be greatly appreciated.
   
  Paul Rousseau

 
 See XML::Rules in the filter mode.
 
 Jenda
 = je...@krynicky.cz === http://Jenda.Krynicky.cz =
 When it comes to wine, women and song, wizards are allowed 
 to get drunk and croon as much as they like.
   -- Terry Pratchett in Sourcery
 
 ___
 Perl-Win32-Users mailing list
 Perl-Win32-Users@listserv.ActiveState.com
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

How to Use XML::Parser to Reduce an XML file to what is wanted

2012-10-31 Thread Paul Rousseau

Hello Users.
 
I have an .xml file that I want to search for specific items, ignoring the 
remaining items. I have dumped the .xml file using the tree method. Partial 
results look as follows:
 
$VAR1 = [
  'Session',
  [
{},
'Hostname',
[
  {
'RemoteHost' = 'SCADA',
'Remote' = '0'
  },
  'Server',
  [
{
  'GroupCount' = '1',
  'Connected' = '1',
  'Name' = 'Kepware.KEPServerEX.V5'
},
'Group',
[
  {
'PercentDeadband' = '0.00',
'Connected' = '2',
'TimeBias' = '-420',
'ItemCount' = '26283',
'Active' = '-1',
'ReqUpdateRate' = '1',
'Name' = '11-30'
  },
  'Item',
  [
{
  'ReqDataType' = '0',
  'AccessPath' = '',
  'Active' = '-1'
},
0,
'11-30.PLC.Global.EY_01_1001'
  ],
  'Item',
  [
{
  'ReqDataType' = '0',
  'AccessPath' = '',
  'Active' = '-1'
},
0,
'11-30.PLC.Global.Always_Off_Bit'
  ],

.
.
. (There are many items so I did not include all of them.
.
.
  'Item',
  [
{
  'ReqDataType' = '0',
  'AccessPath' = '',
  'Active' = '-1'
},
0,
'11-30.PLC.Global.PSHH_01_1010.ClassCTimer.CTL_x.CTL_11'
  ]
]
  ]
]
  ]
];

I want to be able to maintain the .xml file integrity, so I want to open the 
original and after finding what I am looking for, dump the results to a second 
file.
 
As an example, the file has many Item entries with the text, 
 
  'Item',
  [
{
  'ReqDataType' = '0',
  'AccessPath' = '',
  'Active' = '-1'
},
0,
'11-30.PLC.Global.ACKNOWLEDGE.Latched'
  ],

I want to be able to parse the original .xml file, find all items that contain 
the text, '.Latched', and output the results similar to the following:
 
 
$VAR1 = [
  'Session',
  [
{},
'Hostname',
[
  {
'RemoteHost' = 'SCADA',
'Remote' = '0'
  },
  'Server',
  [
{
  'GroupCount' = '1',
  'Connected' = '1',
  'Name' = 'Kepware.KEPServerEX.V5'
},
'Group',
[
  {
'PercentDeadband' = '0.00',
'Connected' = '2',
'TimeBias' = '-420',
'ItemCount' = '26283',
'Active' = '-1',
'ReqUpdateRate' = '1',
'Name' = '11-30'
  },
  'Item',
  [
{
  'ReqDataType' = '0',
  'AccessPath' = '',
  'Active' = '-1'
},
0,
'11-30.PLC.Global.ACKNOWLEDGE.Latched'
  ],
  'Item',
  [
{
  'ReqDataType' = '0',
  'AccessPath' = '',
  'Active' = '-1'
},
0,
'11-30.PLC.Global.EY_01_1001.Latched'
  ]
]
  ]
]
  ]
];

I checked the Net but did not find an extraction example that maintains the 
.xml integrity.
 
I am thinking I would need logic to do the following.
 
1. Open the .xml file.
2. Begin parsing.
3. If the object is not 'Item', keep it. (This will keep objects such as 
'Session', 'Server', 'Group')
4. If the object is 'Item', and it contains the text, '.Latched', keep it.
5. Otherwise, ignore 'Item'
6. Open the output file.
7. Write out all the kept items.
8. Close both files.
 
Any help would be greatly appreciated.
 
Paul Rousseau
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http

RE: How to push a hash on to a hash of array entries

2011-11-08 Thread Paul Rousseau

Hello Gabor,
 
   you are correct on using the square brackets as opposed to the round 
brackets.
 
 $days{$day} = [$hour, $text];

Here is the Dumper output when I use the code,
 
push @{$project{$projectno}}, %days;

 
$VAR1 = {
  '2011-0101' = [
   'SCADA Host Re-evaluation Project',
   14,
   3,
   '6',
   [
 '4.00',
 ''
   ],
   '3',
   [
 '6.00',
 ''
   ],
   '5',
   [
 '4.00',
 ''
   ]
 ]
};
 
It does flatten out as you stated.
 
Here is the Dumper output when I use the code,
 
push @{$project{$projectno}}, \%days;
 
$VAR1 = {
  '2011-0101' = [
   'SCADA Host Re-evaluation Project',
   14,
   3,
   {
 '6' = [
  '4.00',
  ''
],
 '3' = [
  '6.00',
  ''
],
 '5' = [
  '4.00',
  ''
]
   }
 ]
};
 
 
When I execute the line,
 
print Dumper \%{$project{$projectno}[2]};
 
I still get the error,
 
Can't use string (3) as a HASH ref while strict refs in use at 
c:\images\mactimesheet.pl line 40
1, STDIN line 1.
 
I will continue to experiment with the semantics. I believe I am close.
 
Paul
 
 
 

 

 Date: Tue, 8 Nov 2011 02:26:17 +0200
 Subject: Re: How to push a hash on to a hash of array entries
 From: szab...@gmail.com
 To: paulrousseau...@hotmail.com
 CC: perl-win32-users@listserv.activestate.com
 
 Hi Paul,
 
 there are a couple of issues I could see in the code you sent,
 let me point out some of them and hope those will help.
 
 In general I'd recommend using the Dumper function of Data::Dumper
 to check what kind of data structure you got.
 
 
 
 On Tue, Nov 8, 2011 at 1:41 AM, Paul Rousseau
 paulrousseau...@hotmail.com wrote:
  Hello Perl Community,
 
 I want to build a complex hash.
 
  I want my hash structure to look like this:
 
  # %project = (projectno1 = [projdesc1,
  #   hourtotal1,
  #   %days1 = (day x =
  [hours,desc],
  #   day y =
  [hours, desc]
  #  )
  # ],
  #  projdesc2,
  #   hourtotal2,
  #   %days2 = (day x =
  [hours,desc],
  #   day y =
  [hours, desc]
  #  )
  # ]
  # )
 
  I am having trouble building up and populating the individual %days hash.
 
  Here is what I have so far.
 
  use strict;
 
 I'd recommend adding use warnings; as well.
 
 
  my (
%project,
$projectno, $desc,
$day,
%days,
$i
   );
 
  $projectno = 12345;
  $desc = testing first project;
 
  $project{$projectno} = [$desc, 0];   # zero hours
 
  #later on, my code reads in some records such as
 
  # 3, 12, painted a room
  # 5, 6, added a chair
  # 14, 2, made some calls
 
  # for, say, project 12345
 
  For my first test, I populated a smaller hash called %days.
 
  for ($i = 1; $i =3; $i++)
 {
  ($day, $hour, $text) = split (',', inline);
   $days{$day} = ($hour, $text);
 }
 
 
 If I am not mistaken you want to pass an array reference there
 and not an array so need square brackets:
 
 $days{$day} = [$hour, $text];
 
 Try this:
 use Data::Dumper qw(Dumper);
 print Dumper \%days;
 
 
 
  #
  # now that I have finished populating a smaller hash, I want to copy the
  hash on to the bigger hash.
  #
 
  push @{$project{$projectno}}, %days;
 
 In this case perl will flatten the hash and you will push all the keys
 and values of it to the array.
 Try printing out the result with the Dumper.
 
 I am almost sure you will want to write:
 
 push @{$project{$projectno}}, \%days;
 
 See the back-slash in-front of the hash.
 
 
 regards
 Gabor
 
 -- 
 Gabor

How to push a hash on to a hash of array entries

2011-11-07 Thread Paul Rousseau

Hello Perl Community,
 
   I want to build a complex hash.
 
I want my hash structure to look like this:
 
# %project = (projectno1 = [projdesc1,
#   hourtotal1,
#   %days1 = (day x = 
[hours,desc],
#   day y = 
[hours, desc]
#  )
# ],
#  projdesc2,
#   hourtotal2,
#   %days2 = (day x = 
[hours,desc],
#   day y = 
[hours, desc]
#  )
# ]
# )

I am having trouble building up and populating the individual %days hash.
 
Here is what I have so far.
 
use strict;
 
my (
  %project,
  $projectno, $desc,
  $day,
  %days,
  $i
 );
 
$projectno = 12345;
$desc = testing first project;
 
$project{$projectno} = [$desc, 0];   # zero hours

#later on, my code reads in some records such as 
 
# 3, 12, painted a room
# 5, 6, added a chair
# 14, 2, made some calls
 
# for, say, project 12345
 
For my first test, I populated a smaller hash called %days.
 
for ($i = 1; $i =3; $i++)
   { 
($day, $hour, $text) = split (',', inline);
 $days{$day} = ($hour, $text);
   }
 
#
# now that I have finished populating a smaller hash, I want to copy the hash 
on to the bigger hash.
#
 
push @{$project{$projectno}}, %days;
 
Now I want to access the description field. So, if I know the project number 
and I know the day, how do I assign the description? So,
 
$projectno = 12345;
$day = 5;
#
# the next line fails to print out added a chair
 
print ${$project{$projectno}[2]}{$day};
 
I get the error, 
 
Can't use string (3) as a HASH ref while strict refs in use at 
c:\images\mactimesheet.pl line 40
1, STDIN line 1.
 
I believe that the third entry for each project number key is the %days hash.
 
I suspect I have a minor semantic error. I was hoping my print statement would 
have printed an array contaning (6, added a chair).
 
The part, ${$project{$projectno}[2]}, I was thinking refers to the hash 
address; then the part, {$day}, is the key.
 
Then again, maybe I am going at it all wrong with the push statement.
 
Any help would be appreciated.
 
Thank you
 
Paul
 
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


How to split up a string with carriage returns into an array

2011-11-04 Thread Paul Rousseau

Hello Perl Community,
 
   I have string variable, $msg, assigned the following text. 
 
OCT 31 - Attended CSP weekly meeting. Engaged in third party SCADA host (ZedI) 
problem in Fairview district
NOV 1 - Preparation and attendance of Normandville Phase 1 meetings.
NOV 2 - Maintained project list. Troubleshoot software licensing issues.
NOV 3 - Attended COG facilities meeting. Follow-up of Autosol software licenses.
 
 
I want to split the string into an array just as it looks. The string does have 
carriage returns in it.
 
I  tried 
 
@ans = split (/\r/s, $msg);

@ans = split (/\r/g, $msg);

@ans = split (/\r\n/s, $msg);
 
@ans = split (/\r\n/g, $msg);
 
and I get no split.
 
For some reason, the regexp can't find the carriage return and/or line feed.
 
Now I'm thinking about somehow splitting the string using \w{3}\s\d+\s-\s
 
Would a look-behind assertion be better?
 
Perhaps a map function call?
 
Thank you.
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: How to split up a string with carriage returns into an array

2011-11-04 Thread Paul Rousseau

Well Community,
 
   The string that I thought was using carriage return/line feeds actually does 
not have any in them.
 
(I had copied the message string from within an HTM file, and by pasting it, 
the lines broke up accordingly. Naturally, that led me to believe there were 
CR/LFs in the string.)
 
I forgot to mention I use the following code to assign $msg.
 
$msg = $element-as_trimmed_text();
 
(where element points to this line in an htm file.)
 
 td class=CommentGrid colspan=20textarea name=WeekRow1:CommentTextBox 
id=WeekRow1_CommentTextBox title=Please Write Comment Here 
class=CommentTextbox onchange=OnCommentChange (1); return false; 
onclick=OnCommentTextboxClick (1); return false; 
ondblclick=OnCommentTextboxClick (1); return false; 
style=border-style:None;font-family:Arial Unicode 
MS;font-size:15px;height:100%;width:100%;display:inlineOCT 31 - Attended CSP 
weekly meeting. Engaged in third party SCADA host (ZedI) problem in Fairview 
district
NOV 1 - Preparation and attendance of Normandville Phase 1 meetings.
NOV 2 - Maintained project list. Troubleshoot software licensing issues.
NOV 3 - Attended COG facilities meeting. Follow-up of Autosol software 
licenses./textarea
 /td

 
The effect of the as_trimmed_text call made the cr/lf's disappear.
 
(I found out they were missing when I executed a single character dump on $msg 
using this code:
 
while($msg =~/./g)
  {
print $ and  . ord($);
  }

Thanks to Perl monks)
 
So, in reality, $element- as_trimmed_text() causes $msg to be one big string. 
For example,
 
$msg = OCT 31 - Attended CSP weekly meeting. Engaged in third party SCADA host 
(ZedI) problem in Fairview district NOV 1 - Preparation and attendance of 
Normandville Phase 1 meetings. NOV 2 - Maintained project list. Troubleshoot 
software licensing issues. NOV 3 - Attended COG facilities meeting. Follow-up 
of Autosol software licenses.
 
Now, I could traverse the string, word by word, until I encounter a known month 
abbreviation, then push that chunk of $msg on to the array.
 
Or, I could look for the pattern MMM D or MMM DD, then any text following up to 
the next MMM.
 
So this leads me to want to use some sort of look-ahead assertion regexp.
 
Does anyone have a suggestion? Should I simply just set up a for loop and hack 
away on getting $msg into @ans?
 
Paul

 



From: paulrousseau...@hotmail.com
To: perl-win32-users@listserv.activestate.com
Subject: How to split up a string with carriage returns into an array
Date: Fri, 4 Nov 2011 12:07:57 -0600





Hello Perl Community,
 
   I have string variable, $msg, assigned the following text. 
 
OCT 31 - Attended CSP weekly meeting. Engaged in third party SCADA host (ZedI) 
problem in Fairview district
NOV 1 - Preparation and attendance of Normandville Phase 1 meetings.
NOV 2 - Maintained project list. Troubleshoot software licensing issues.
NOV 3 - Attended COG facilities meeting. Follow-up of Autosol software licenses.
 
 
I want to split the string into an array just as it looks. The string does have 
carriage returns in it.
 
I  tried 
 
@ans = split (/\r/s, $msg);

@ans = split (/\r/g, $msg);

@ans = split (/\r\n/s, $msg);
 
@ans = split (/\r\n/g, $msg);
 
and I get no split.
 
For some reason, the regexp can't find the carriage return and/or line feed.
 
Now I'm thinking about somehow splitting the string using \w{3}\s\d+\s-\s
 
Would a look-behind assertion be better?
 
Perhaps a map function call?
 
Thank you.
 

___ Perl-Win32-Users mailing list 
Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: 
http://listserv.ActiveState.com/mailman/mysubs  
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: How to Extract a Date from a File

2011-11-03 Thread Paul Rousseau

Thank you Brian.
 
Your reply is indeed most eloquent.
 
Jon Bjornstad has offered a more traditional regexp solution that I hope to 
comprehend, if only to sharpen my Perl skills. (I am waiting for his response 
to my lack thereof.)

I hope to test and share Jon's answer with the community. For now, I will 
leverage the HTML library APIs.
 
Sincerely,
 
Paul
 


 From: bra...@nyx.com
 To: perl-win32-users@listserv.activestate.com
 Date: Thu, 3 Nov 2011 10:37:03 +
 Subject: RE: How to Extract a Date from a File
 
 From: perl-win32-users-boun...@listserv.activestate.com 
 [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Paul 
 Rousseau
 Sent: 02 November 2011 16:08
 To: perl Win32-users
 Subject: How to Extract a Date from a File
 
  Hello Perl folks,
 
 
  I would like to know if there is an eloquent way of extracting a date 
  string from a file.
 
  My code goes like this:
 
  open (INFILE, $sourcedir\\$filename) || die Can not open 
  $sourcedir\\$filename $!\n;
  @filecontents = INFILE;
  close INFILE;
  @filecontents = map {chomp; $_} @filecontents;
 
  #
  # Within the file contents, look for the text, CurrentWeekLabel
  #
  # Here is a text sample.
  #
  # div style=TEXT-ALIGN: center; min-width: 750px
  # div style=OVERFLOW: hidden; HEIGHT: 20px; TEXT-ALIGN: centerspan 
  id=CurrentWeekLabelWeek Of:
  /spanspan id=StartWeekLabel 
  style=font-weight:bold;2011/10/29/spanspan id=Label6 style=font-
  weight:bold; - /spanspan id=EndWeekLabel 
  style=font-weight:bold;2011/11/04/span/div
  # div style=OVERFLOW: hidden; HEIGHT: 24px; TEXT-ALIGN: centera 
  id=PreviousWeekLinkButton
  class=LinkButton href=javascript:OnPreviousWeekLinkButtonClick ()
  href=javascript:__doPostBack('PreviousWeekLinkButton','')Prev/aspan 
  id=Label20nbsp;|nbsp;/spana  
  onclick=SelectWeekButtonClick('PopupCalendar1', 'SelectWeekLinkButton'); 
  return false;
  id=SelectWeekLinkButton class=LinkButton 
  href=javascript:__doPostBack('SelectWeekLinkButton','')Select  
  Week/aspan id=Label8nbsp;|nbsp;/spana id=NextWeekLinkButton 
  class=LinkButton
  href=javascript:OnNextWeekLinkButtonClick ()
  href=javascript:__doPostBack('NextWeekLinkButton','')Next/a/div
  # div style=OVERFLOW: hidden; OVERFLOW:visible; TEXT-ALIGN: centerspan 
  id=StatusLabel
  class=StatusLabel/span/div
  # /div
  #
  # Obtain the year, month and day following the text, StartWeekLabel
  #
  @ans = grep (/StartWeekLabel.+\(\d{4})\/(\d{2})\/(\d{2})\\/span/si, 
  @filecontents);
  #
  # Build the start date from the matches.
  #
  $start_date = $1 . $2 . $3
 
  I was wondering if there was a neat way to avoid using @ans as a temporary 
  variable, and extract the
  2011/10/29 straight into $start_date so that $start_date = 20111029
 
 Using regular expressions is not usually recommended. Prefer to use the 
 modules that specialise in doing that. Also, there may be alternate ways to 
 extract the date elements, and modules to validate them. For example...
 
 ---
 use strict;
 use warnings;
 
 use HTML::TreeBuilder;
 use Date::Calc qw{check_date};
 
 my $root = HTML::TreeBuilder-new_from_file(*DATA);
 defined $root or die Failed to parse\n;
 my $element = $root-look_down(id, StartWeekLabel);
 defined $element or die Failed to locate id=StartWeekLabel\n;
 my $rawdate = $element-as_trimmed_text();
 print Raw date '$rawdate'\n;
 my @date = split /, $rawdate;
 if ((check_date(@date))) {
 print Date looks OK: ', @date, '\n;
 }
 else {
 print That date looks invalid\n;
 }
 
 __DATA__
 div style=TEXT-ALIGN: center; min-width: 750px
 div style=OVERFLOW: hidden; HEIGHT: 20px; TEXT-ALIGN: centerspan 
 id=CurrentWeekLabelWeek Of: /spanspan id=StartWeekLabel 
 style=font-weight:bold;2011/10/29/spanspan id=Label6 
 style=font-weight:bold; - /spanspan id=EndWeekLabel 
 style=font-weight:bold;2011/11/04/span/div
 div style=OVERFLOW: hidden; HEIGHT: 24px; TEXT-ALIGN: centera 
 id=PreviousWeekLinkButton class=LinkButton 
 href=javascript:OnPreviousWeekLinkButtonClick () 
 href=javascript:__doPostBack('PreviousWeekLinkButton','')Prev/aspan 
 id=Label20nbsp;|nbsp;/spana 
 onclick=SelectWeekButtonClick('PopupCalendar1', 'SelectWeekLinkButton'); 
 return false; id=SelectWeekLinkButton class=LinkButton 
 href=javascript:__doPostBack('SelectWeekLinkButton','')Select 
 Week/aspan id=Label8nbsp;|nbsp;/spana id=NextWeekLinkButton 
 class=LinkButton href=javascript:OnNextWeekLinkButtonClick () 
 href=javascript:__doPostBack('NextWeekLinkButton','')Next/a/div
 div style=OVERFLOW: hidden; OVERFLOW:visible; TEXT-ALIGN: centerspan 
 id=StatusLabel class=StatusLabel/span/div
 /div
 ---
 
 --
 Brian Raven
 
 
 
 
 Please consider the environment before printing this e-mail.
 
 This e-mail may contain confidential and/or privileged information. If you 
 are not the intended recipient or have received this e-mail in error, please 
 advise the sender

How to Extract a Date from a File

2011-11-02 Thread Paul Rousseau

Hello Perl folks,
 
 
I would like to know if there is an eloquent way of extracting a date string 
from a file.
 
My code goes like this:
 
   open (INFILE, $sourcedir\\$filename) || die Can not open 
$sourcedir\\$filename $!\n;
   @filecontents = INFILE;
   close INFILE;
   @filecontents = map {chomp; $_} @filecontents;

#
# Within the file contents, look for the text, CurrentWeekLabel
#
# Here is a text sample.
#
#   div style=TEXT-ALIGN: center; min-width: 750px
#div style=OVERFLOW: hidden; HEIGHT: 20px; TEXT-ALIGN: centerspan 
id=CurrentWeekLabelWeek Of: /spanspan id=StartWeekLabel 
style=font-weight:bold;2011/10/29/spanspan id=Label6 
style=font-weight:bold; - /spanspan id=EndWeekLabel 
style=font-weight:bold;2011/11/04/span/div
#div style=OVERFLOW: hidden; HEIGHT: 24px; TEXT-ALIGN: centera 
id=PreviousWeekLinkButton class=LinkButton 
href=javascript:OnPreviousWeekLinkButtonClick () 
href=javascript:__doPostBack('PreviousWeekLinkButton','')Prev/aspan 
id=Label20nbsp;|nbsp;/spana 
onclick=SelectWeekButtonClick('PopupCalendar1', 'SelectWeekLinkButton'); 
return false; id=SelectWeekLinkButton class=LinkButton 
href=javascript:__doPostBack('SelectWeekLinkButton','')Select Week/aspan 
id=Label8nbsp;|nbsp;/spana id=NextWeekLinkButton class=LinkButton 
href=javascript:OnNextWeekLinkButtonClick () 
href=javascript:__doPostBack('NextWeekLinkButton','')Next/a/div
#div style=OVERFLOW: hidden; OVERFLOW:visible; TEXT-ALIGN: centerspan 
id=StatusLabel class=StatusLabel/span/div
#   /div
#
# Obtain the year, month and day following the text, StartWeekLabel
#
  @ans = grep (/StartWeekLabel.+\(\d{4})\/(\d{2})\/(\d{2})\\/span/si, 
@filecontents);
#
# Build the start date from the matches.
#
$start_date = $1 . $2 . $3
 
I was wondering if there was a neat way to avoid using @ans as a temporary 
variable, and extract the 2011/10/29 straight into $start_date so that 
$start_date = 20111029
 
Thank you
 
Paul Rousseau
403 776 4293
  ___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


HTML Parsing Question

2010-02-04 Thread Paul Rousseau

Hello,

 

   I have an HTML file that contains the following snippet:

 

group name=Group1 visible=true wallpaper=false toolTipText= 
exposeToVba=notExposed isReferenceObject=true linkSize=true 
linkConnections=true linkAnimations=linkWithoutExpression 
linkBaseObject=System_Bar.Group1
button name=Button1 height=25 width=85 left=8 top=10 
visible=true toolTipText= exposeToVba=notExposed isReferenceObject=true 
linkSize=true linkConnections=true linkAnimations=linkWithoutExpression 
linkBaseObject=System_Bar.Button1 style=recessed captureCursor=false 
highlightOnFocus=true tabIndex=1
command pressAction=Display Overview repeatAction= 
releaseAction= repeatRate=0.25/
up patternColor=black patternStyle=none backColor=#ECE9D8 
backStyle=solid foreColor=black
caption fontFamily=Arial fontSize=8 bold=true 
italic=false underline=false strikethrough=false caption=Overviews/
imageSettings imageReference=noImage/
/up
down downSameAsUp=true patternColor=black patternStyle=none 
backColor=#ECE9D8 backStyle=solid foreColor=black
caption fontFamily=Arial fontSize=10 bold=false 
italic=false underline=false strikethrough=false caption=/
imageSettings imageReference=noImage/
/down
/button
button name=Button24 height=25 width=85 left=95 top=10 
visible=true toolTipText= exposeToVba=notExposed isReferenceObject=true 
linkSize=true linkConnections=true linkAnimations=linkWithoutExpression 
linkBaseObject=System_Bar.Button24 style=recessed captureCursor=false 
highlightOnFocus=true tabIndex=2
command pressAction=Display Oil_Treating_Overview 
repeatAction= releaseAction= repeatRate=0.25/
up patternColor=black patternStyle=none backColor=#ECE9D8 
backStyle=solid foreColor=black
caption fontFamily=Arial fontSize=8 bold=true 
italic=false underline=false strikethrough=false caption=Oil Treating/
imageSettings imageReference=noImage/
/up
down downSameAsUp=true patternColor=black patternStyle=none 
backColor=#ECE9D8 backStyle=solid foreColor=black
caption fontFamily=Arial fontSize=10 bold=false 
italic=false underline=false strikethrough=false caption=/
imageSettings imageReference=noImage/
/down
/button
  .

  .

  . 

/group


 

I want to obtain the parent name for all button tags. I am having trouble 
extracting the parent name. For example, I can find Button1 and Button24 
but I can not get to either item's parent name, Group1. 

 

Here is my code so far. (I believe it's something trivial; I feel I am so 
close.)

 

foreach $filename (@filenames)
  {
print filename is $filename;
   $tree = HTML::TreeBuilder-new();
   $tree-parse_file($sourcedir\\$filename);

   @Ans = $tree-look_down('_tag' = 'button');
   foreach $button (@Ans)
 {

print button is  . $button-attr('name');   # prints button is 
Button1
print button tag is  . $button-tag;  # can also use ${$button}{_tag}   # 
prints button tag is button
print button parent hash pointer is  . $button-parent;   # can also use 
${$button}{_parent} # prints button parent hash pointer is 
HTML::Element=HASH(0x1afa5c4)

#

#print Dumper($button-parent);

#

foreach $key (keys %{$button-parent})
  {
   print key is $key; # prints four keys: _parent, _content, 
_tag, _implicit
  }
print button _parent value is  . ${$button}{_parent};  # prints button 
_parent value is HTML::Element=HASH(0x1afa5c4)
print button _tag value is  . ${$button}{_tag};  # prints button _tag value 
is button


  $parent = $button-parent;
print parent tag is  . ${$parent}{_tag}; # prints parent tag is body
print parent content is  . ${$parent}{_content};   # prints parent content 
is ARRAY(0x1afa7b0)
foreach $key (@{${$parent}{_content}})
   {
#print content item is $key;
   }

#print parent name is  . $parent-attr('name');

  $groupid = $button-look_up('_tag', = 'group');
#  print group id is  . $groupid;
 }

#   $tree-dump;

# print $tree-as_HTML;

  }


 

 

Any help would be appreciated.

 

Thank you

 

Paul Rousseau

 
  
_
Check your Hotmail from your phone.
http://go.microsoft.com/?linkid=9708121___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


How to handle a find failure when examining an excel file

2007-11-27 Thread Paul Rousseau

Hello,
 
   I want my code to be able to handle the following find statement when it 
fails to find the text in the 'What' argument.
 
   $row = $Sheet-UsedRange-Find ({What = ParentItemName, SearchDirection 
= xlNext, SearchOrder = xlByRows}) - {Row};
If the text, ParentItemName, does not exist in the affected worksheet, I get 
the following hash error.
 
 
 
Can't use an undefined value as a HASH reference at c:\images\PKSortExport.pl 
line 441, STDIN line 2
 
 
 
 
I could bog you down with the rest of the code, but it might better if someone 
could simply send me a link to the basic code to handle a find failure when 
using Perl to look in a workbook's worksheet for a string.
 
Thank you.
 
 
 
_
Are you ready for Windows Live Messenger Beta 8.5 ? Get the latest for free 
today!
http://entertainment.sympatico.msn.ca/WindowsLiveMessenger___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Username and password lookup

2006-05-31 Thread Paul Rousseau

Hello,

  I am looking for a way to take a userid and password, and verify them 
against the OS.


I have looked at Win32::NetAdmin's UserGetAttributes function; however, when 
I read a valid userid's information, I get nothing back for the password 
field.


The idea was to read the password, compare it to the one entered, then 
validate appropriately. The more I think about this, the less likely the 
user id's password would be presented in full text.


So, to cut to the chase, is there a resource kit tool or some exe that takes 
a userid, password and possibly a domain name, and returns a one or zero? I 
don't mind using a Perl PM either.


(I searched the Net for quite some time looking for a simple, command-line 
authentication tool, but did not find anything. That is why I am now turning 
to Perl.)


I am looking for something like

 $retval = qx { CheckUser.exe $domain, $userid, $password};
 if $retval == 1
{
 print domain:User id:password is valid;
}


Or equivalent Perl function call like

use this::that qw (CheckUser);
my ($domain, $userid, $password, $retval);
  .
  .
  .
  .

$retval = CheckUser ($domain, $userid, $password);


Much obliged.


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Regex Needed

2006-03-24 Thread Paul Rousseau

Hello,

  I am looking for help on a regex that examines strings such as

xxxN yyy sssNNN
xxxN yyyNyyy sss
xxxN yyyNyyy ssN

and returns only the sss part?  N is always a numeral, and s is always 
alphabetic.


Here is what I have so far as an example. I believe there is an eloquent way 
to do this in a single regex.


my (
 $string,
 $prefix
);

$string = MBH1 WELL PIT050;
($prefix) = $string =~    # I want $prefix to equal PIT

Thank you.


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


How to clear up blanks when converting an array to a hash

2006-03-21 Thread Paul Rousseau

Hello,

  I run an executable that returns a small array of data.

my @ans = qx {myexec};

@ans contains the values,

Value= 1
Status   = 13
Options = 0x0a
Quality = 3

I use a map function to convert this array into a hash.

my %results = map {(split /=/)} @ans;

My questions are:

1. How to I get rid of the blanks on either side of the key and the value?
2. How do I also get rid of the CRLF in the value?


I want to be able to reference my hash using something like

if ($results{Status} == 9)
  {
   print value, $results{Value}, is good;
  }

I may have a syntax error question too: i.e. do I need to double quote the 
key? e.g. if ($results{Status} == 9)


Any help would be greatly appreciated.

Thank you.


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


How to best replace one string with another in a text file

2006-02-28 Thread Paul Rousseau

Hello,

 I want to open a text file, look for a specific string, replace it with a 
new string, and write the line out to another file. For lines not containing 
the specific string, I want to write out as is.


I was wondering if it is possible to do it with a map or splice or grep 
command rather than a foreach loop.


Perhaps, I should be looking at some executable that replaces one string 
with another within a file?


I have resorted to a foreach loop.

Here is a snippet of my code:

  $currnodename = AMACHINE;
  $oldnodename = BMACHINE;
  $infile = $ENV{FT}\\qld\\$msg.qli;
  $outfile = $ENV{TEMP} . \\$task.tmp;

  open (INFILE, $infile) || die Can not open $infile;
  open (OUTFILE, +$outfile) || die Unable to open $outfile;
  while ($inline = INFILE)
 {
  chomp $inline;
  $inline =~ s/$oldnodename/$currnodename/g;
  print OUTFILE $inline;
 }
  close INFILE;
  close OUTFILE;


Thank you


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Hash, sort and map function problem

2002-12-13 Thread Paul Rousseau
Hello,

  I have a hash that looks like this:

 my %sql_hash = (A = [2, 6, ],
 Q = [1, 3, ],
 D = [5, 8, ],
 X = [4, 2, ],
 P = [3, 12, ]);

The key is an arbitrary string (e.g. D). The key order is not determined 
by this key string, but by the number in the first value of the associated 
array value.

For example, the following code sorts the hash based on the values 2, 1, 5, 
4 ,3 you see above, and prints out The keys are: Q A P X D

my $c;
print keys are: ;
foreach $c (sort {$sql_hash{$a}-[0] = $sql_hash{$b}-[0]} keys 
%sql_hash)
  {
   print $c ;
  }

For many of you, this is standard Perl stuff.

What I want to do is take the second entry in each value array (i.e. 6, 3, 
8, 2, 12), and use it to break up a long string using the substr function 
(or some other function); place each chunk in the third entry of each value 
array, and base it on the sorting position of the first value.

In other words, sort the hash in the proper order,

 foreach $c (sort {$sql_hash{$a}-[0] = $sql_hash{$b}-[0]} keys 
%sql_hash)

then somehow, pick up the second array value for each key-value pair, add it 
to a running $offset variable, and apply the command,

$sql_hash{$c}-[3] = substr ($mystring, $offset, $sql_hash{$c}-[2]);

where $mystring = stuff  some blanks some words more stuff ;

In the end, my hash looks like

%sql_hash = (A = [2, 6, ff  so],
 Q = [1, 3, stu],
 D = [5, 8,  words mo],
 X = [4, 2, me],
 P = [3, 12, me blanks so]);


I have been looking at the map function to do this, but maybe there is a 
better approach. I thought about sorting the hash first (based on the first 
value) into an array, then using a foreach loop to obtain the second value, 
add it to a running $offset variable, and applying the substr command to 
update the third value.

Any help would be greatly appreciated.

Thank you

Paul Rousseau


_
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs