- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Strange print behaviour in perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 03:05 PM
тАО02-09-2009 03:05 PM
Strange print behaviour in perl
We are developing a checking script written in perl, it runs some scripts on a host then emails the output as csv to allow it to be imported in to excel.
The report is started with:
open(MAILX,"|/usr/bin/mailx -s \"$type Handover report for $host\" $email");
print MAILX "$host: $uname\n\n $r/$c checks failed, details below:\n\n";
foreach(@$errors) {
print MAILX "\t$_\n\n";
Then it runs through thte output from each script, creating the csv details, see example below:
print MAILX "23,HW/ OS,OS (Red Hat),(Red Hat Linux specific item / TBD) t ," ;
if($results->[23]{result})
{ print MAILX "$results->[23]{result}"; }
print MAILX "," ;
if($results->[23]{error})
{ print MAILX "$results->[23]{error}"; }
print MAILX "\n"; <+++++++++++
print MAILX "24,HW/ OS,OS (SuSE),(SuSE Linux specific item / TBD) ," ;
if($results->[24]{result})
{ print MAILX "$results->[24]{result}"; }
print MAILX "," ;
if($results->[24]{error})
{ print MAILX "$results->[24]{error}"; }
print MAILX "\n";
The creates output like:
.
.
6,HW/ OS,General,OS internal disk mirroring configured properly ,FAIL,/dev/vg00/lvolu11 not mirrored.
.
.
23,HW/ OS,OS (Red Hat),(Red Hat Linux specific item / TBD) t ,N/A,NON-HPUX
24,HW/ OS,OS (SuSE),(SuSE Linux specific item / TBD) ,N/A,NON-HPUX
25,Backup,Backup,scheduled filesystem backup configured and working ,PASS,OK
However - Sometimes the newline marked with <+++++++ fails to show in the email. The new line is wholly dependent on the line ending TBD) t ," ;
If there are less than 3 spaces before the comma the newline fails to print. The t is in there for testing purposes. Any Ideas why?
We are having similar problems with other lines, too, some seem to require 4 spaces before the comma, others are happy with 2.
Anyone come across this before?
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 03:32 PM
тАО02-09-2009 03:32 PM
Re: Strange print behaviour in perl
This doesn't make sense. Have you set the 'stict' and 'warnings' pragma in your script? If not, at least for the purposes here do 'use warnings;'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 03:36 PM
тАО02-09-2009 03:36 PM
Re: Strange print behaviour in perl
I added "use warnings;" near the top and got an error:
Can't locate warnings.pm in @INC
So give me a few minutes with my good friend google....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 03:37 PM
тАО02-09-2009 03:37 PM
Re: Strange print behaviour in perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 03:39 PM
тАО02-09-2009 03:39 PM
Re: Strange print behaviour in perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 03:41 PM
тАО02-09-2009 03:41 PM
Re: Strange print behaviour in perl
> Can't locate warnings.pm in @INC
This would suggest that your version of Perl is very old. To see your version, do:
# perl -v
In lieu of the 'warnings' pragma, you can use the older:
#!/usr/bin/perl -w
...at the interpreter line.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 04:19 PM
тАО02-09-2009 04:19 PM
Re: Strange print behaviour in perl
My guess is that your data-dependent behavior may involve things like carriage-return (\r) or backspace (\010) characters.
For example:
# perl -e 'print STDERR "hi","\r";print "?\n"'
?i
You might try adding an automatic linefeed to print statements with the '-l' switch. Hence on your shebang (interpreter line):
#!/usr/bin/perl -wl
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 04:23 PM
тАО02-09-2009 04:23 PM
Re: Strange print behaviour in perl
Does "printf" work in perl?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 04:36 PM
тАО02-09-2009 04:36 PM
Re: Strange print behaviour in perl
2) 5.005_03
That's wicked old.
Not having looked for a solid timeline,
I would guess over 10 years.
5.6 was normal 5 years back, 5.8 pretty standard. 5.10 desirable most platforms.
Just a gutfeel.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-09-2009 04:43 PM
тАО02-09-2009 04:43 PM
Re: Strange print behaviour in perl
> Does "printf" work in perl?
Yes, and that would be the most appropriate way to handle your needs. The 'printf' function works just like you would expect.
Regards!
...JRF...