- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- A little improvement to my webinput perl scripts
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
Forums
Discussions
Discussions
Discussions
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
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
05-20-2004 03:29 PM
05-20-2004 03:29 PM
It works pretty well right now.
I strip out the line feeds as follows so I can put them in with print statements later:
chop ($filedata) if ($filedata =~/\n$/);
In the output file get the following results
this the data^M
This ^M is a single character and I'd like to strip it out.
I know I can do it after the script run with the dos2unix command but I'd rather strip it in the program.
I imagine its another chop statement. I can't begin to figure out what it should be.
Bunny for tested code or an explanation as to why I can't do it.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2004 04:20 PM
05-20-2004 04:20 PM
Re: A little improvement to my webinput perl scripts
This is not recently tested but I remember running into a situtaion like this in a 7 line perl code (this is the extent of my perl capacity goes to tell you the truth) but instead of chop, I remember using chomp to eliminate the trailing carriage return character.
Hope it helps.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2004 04:45 PM
05-20-2004 04:45 PM
Re: A little improvement to my webinput perl scripts
you can use chomp to remove a substring at the end of a line. $\ specifies the substring. or $INPUT_RECORD_SEPARATOR if you use English module.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2004 11:50 PM
05-20-2004 11:50 PM
Re: A little improvement to my webinput perl scripts
A bunny for a working chomp command.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2004 11:51 PM
05-20-2004 11:51 PM
Re: A little improvement to my webinput perl scripts
A bunny for a working chomp command.
attaching a sample
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 12:02 AM
05-21-2004 12:02 AM
Re: A little improvement to my webinput perl scripts
$filedata =~ s/\s+$//;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:03 AM
05-21-2004 01:03 AM
Re: A little improvement to my webinput perl scripts
open(INF,"../links.txt");
@data =
close(INF);
foreach $i (@data) {
chomp($i);
($name,$heading,$text) = split(/\|/,$i);
print "$heading\n";
}
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:16 AM
05-21-2004 01:16 AM
Re: A little improvement to my webinput perl scripts
How about (as suggested by curt)
open FILE, "filename" or die "oh no, not again\n";
$/="^M";
while(
chomp;
print;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:22 AM
05-21-2004 01:22 AM
Re: A little improvement to my webinput perl scripts
I will be trying them late this afternoon.
I'm concerned that Ken's code will remove all whitespaces including the spaces between words.
Since the program is already runnning, my perference if possible is to add a chomp command to the existing statement so I don't have to execute a secondd program.
Perhaps change:
chop ($filedata) if ($filedata =~/\n$/);
to
chop ($filedata) if ($filedata =~/^M\n$/);
except I know its not carat M, its a single character taht I don't know the escape code for.
Thanks. If there are other ideas, I'll be happy to try them.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:28 AM
05-21-2004 01:28 AM
Re: A little improvement to my webinput perl scripts
$\="\r\n";
chomp(filedata);
do for you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:29 AM
05-21-2004 01:29 AM
Re: A little improvement to my webinput perl scripts
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:35 AM
05-21-2004 01:35 AM
Re: A little improvement to my webinput perl scripts
chop ($filedata) if ($filedata =~/^M\n$/);
is only going to remove the \n. leaving the \r. so, your going to still have the same issue that you are now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:36 AM
05-21-2004 01:36 AM
Re: A little improvement to my webinput perl scripts
Apologies though, my little snippet above forgot that there needs to be a line feed in there too :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:48 AM
05-21-2004 01:48 AM
Re: A little improvement to my webinput perl scripts
$\="\r\n";
chomp(filedata);
results in an extra ^M after each line.
I think this is significant.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 01:58 AM
05-21-2004 01:58 AM
Re: A little improvement to my webinput perl scripts
It was interfering with the following problem.
I have a line of data that looks like this.
* * *^M
I wanted to test for text
if ( $filedata eq "* * *") {
# process differently
}
I can close this thread if i can reliabily test the first character of the array for an asterisk and take action.
That code will end this with a bunny.
Got a meeting, point assignment after.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 02:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 02:17 AM
05-21-2004 02:17 AM
Re: A little improvement to my webinput perl scripts
The chomp POD says that chomp() will chop off any string held in the input separator varaible $/.
On Win32 the line separator is the sequence of \r\n or ^M^J.
Perl should automagically take care of the propper separator.
But to be explicit you could assign this char sequence to $/ (better localize $/)
e.g.
{ local $/ = "\r\n";
# parsing, chomping here
}
If you prefer you could as well use the octal or hex reps.
$/ = "\015\012";
or even this might work
$/ = "\cM\cJ";
To get rid of carriage returns it's more efficient to use the transliterate operator as known from awk (tr or y) than a regexp.
while (
tr/\015//d;
...
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 02:26 AM
05-21-2004 02:26 AM
Re: A little improvement to my webinput perl scripts
I'm still going to try to strip that ^M but I've accomplished what I need on this one.
dos2unix works fine as a final processing step.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 02:29 AM
05-21-2004 02:29 AM
Re: A little improvement to my webinput perl scripts
while (
if (/[*]+/) {
# do something
}
}
similarily, treating only lines that don't contain carriage returns
unless (/[\r]/) {
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2004 02:32 AM
05-21-2004 02:32 AM
Re: A little improvement to my webinput perl scripts
You DUDE!
You got it.
after the chop
$/="\cM";
chomp ( $filedata );
I know I could probably do it in one line of code but I don't care.
THREAD CLOSED!
AWESOME
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com