Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two questions in Perl 1

Status
Not open for further replies.

palpanni

Programmer
Nov 30, 2001
5
HU
Hi Everybody,

I am Anna from Hungary and I am a beginner at Perl. I have two questions about it.

My first question is if there is a way to dump or query the printing events from NT system eventlog in Perl at all? Or should i use other language for it? We use the NTCRT terminal emulator program for Unix under NT.

The other question is how to parse the dates by regular expressions:
for example: I want to replace "20011206" to "2001.12.06". The text file which them contains is tab-delimited and each line of it begins the dates. I need to do more replaces at once in the text file.

Thanks in advance,
Yours Sincerely,
Anna Palotás (palpanni@rocketmail.com, panna@borsod.ksh.hu).
 
Anna,

First question - dunno, sorry.

Second.

s/^(....)(..)(..\t)/$1.$2.$3/;
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi Mike,

Thanks for your rapid reply, I will try your second suggestion tomorrow at work.

Till it, have you any suggestion for my first problem? - another scripting languages, for example? I know I could backup the eventlog as evt or csv file, but I need to dump it automatically. I have found the Win32_LogEvent WMI function, but I don't know the event code of the printing event informations to query it by WQL (Query Language of WMI).

I would appreciate any suggestion! :eek:)
Thanks in advance!
Yours Sincerely,
Anna (palpanni@rocketmail.com).
 
Anna - have you had a look at the Win32 modules that come with activeperl? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi Mike,

I am Anna again. I still didn't look at the Win32 modules. I am very beginner at Perl.
I prefer database development with Access to programming, but I have got such a task. My boss wants me to be a sstem administrator.
 
Ok, let me have a dig around - will have to be tomorrow but I will have a look.

Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Anna,

This is from the Perl documentation of the Win32::EventLog module; it looks to be what you need.

The following example illustrates the way in which the EventLog module can be used. It opens the System EventLog and reads through it from oldest to newest records. For each record from the Source EventLog it extracts the full text of the Entry and prints the EventLog message text out.
[tt]
use Win32::EventLog;
$handle=Win32::EventLog->new("System", $ENV{ComputerName})
or die "Can't open EventLog\n";
$handle->GetNumber($recs)
or die "Can't get number of EventLog records\n";
$handle->GetOldest($base)
or die "Can't get number of oldest EventLog record\n";
while ($x < $recs) {
$handle->Read(EVENTLOG_FORWARDS_READ|EVENTLOG_SEEK_READ,
$base+$x,
$hashRef)
or die &quot;Can't read EventLog entry #$x\n&quot;;
if ($hashRef->{Source} eq &quot;EventLog&quot;) {
Win32::EventLog::GetMessageText($hashRef);
print &quot;Entry $x: $hashRef->{Message}\n&quot;;
}
$x++;
}
[/tt]
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi Mike and Happy New Year!

I am Anna again, but with new username &quot;palotasani&quot;. &quot;Palpanni&quot; is out of work because of a Magistr virus in my Yahoo! box. :-( Thanks for your reply, but it's a bit hard for me. I will think about it.

I have another question about SUBSTR. I suppose it is not hard, but i am a beginner at Perl. I have a unix text file with dates and task in it. I want to empty the tasks and to keep only the dates:

wanted: jan-01
instead of: jan-01 TASK1 TASK2 TASK3 TASKN

Jan-01 is the first column of my file. We have to fill the task plan for this year. These tasks mean programs to be runned on a given day.

Thanks in advance!
Yours Sincerely,
Anna (palotasani@yahoo.com)
 
Hi missbarbell and thanks for your answer! Your suggestion was working. :)

I got an other problem in my text file. My log should have Hungarian characters with
accents, but I have got only whitespaces instead of them. For example &quot;O' &quot; (long o) means 4 spaces in my text file.

Well, my question is how to replace spaces within a string to any characters?

Thanks in advance!
Yours Sincerely,
palotasani
 
This maybe because the logfile is being created by a file that doesn't have an extended charcater set for the Hungarian characters you are using, and possible either translates them to spaces or is actually inserting control characters which appear as spaces.

If you know the exact pattern you wish to replace then you can use something like &quot;s/$oldstring/$newstring/g;&quot;, where $oldstring is the pattern of spaces or charcters you are looking for, and $newstring are the Hungarian charcters you wish to replace them with.

If the characters are being replaced with 4 spaces, it maybe difficult to replace exactly how you want to as &quot;s/ /O'/g;&quot; would replace every occurance of 4 space with the &quot;O'&quot; string.

HTH,
Barbie. Leader of Birmingham Perl Mongers
 
Hi missbarbell,

Thanks for your help! This log is an NT eventlog. It maybe countains control characters or spaces. I found a unix script that replaces most of characters to DOS format, but not all of them. It would be very helpful if your suggestion work! My work would take only a few hours instead of days. Rest of my work countain Perl script, DOS batch file and Excel Macros. The outputs are formatted Excel reports with various headings. My boss needs them to control printing.

I will try it at my workplace on Monday! I will write you if it was successful.

Yours Sincerely,
palotasani
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top