- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- PERL - Escape special characters
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
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
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
тАО12-20-2005 05:32 AM
тАО12-20-2005 05:32 AM
PERL - Escape special characters
I have a PERL script which reads inputs from another file. But each line in the input has few special characters which needs to be escaped.
Can anyone tell me the best way to do this?
Is there any package available in PERL which when used automatically escapes special characters.
Thanks,
Anand
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2005 05:46 AM
тАО12-20-2005 05:46 AM
Re: PERL - Escape special characters
I would read the file in raw (binary) mode:
#/usr/bin/perl
my $/ = "\0";
while (<>) {
...
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2005 05:55 AM
тАО12-20-2005 05:55 AM
Re: PERL - Escape special characters
#!/usr/bin/perl
while (<>)
{
chomp;
#Put all special characters in the search pattern
$_ =~ s/([\$\#\@\\])/\\$1/g;
print "$_\n";
}
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2005 06:13 AM
тАО12-20-2005 06:13 AM
Re: PERL - Escape special characters
method 1
open my $file, "< $file_name" or die "$file_name: $!";
binmode $file;
method 2
open my $file, "<:raw", $file_name or die "$file_name: $!";
What you probably MEANT was
local $/; # set's input record separator to undef
my $content = <>; # 'while' is useless
Being escaped is a too wide and unspecific defenition to give a solution for
# insert a backslash in fron of specials
s{([.....])}{\\$1}g;
where ..... is the range of characters that need the \
but you could also mean to `escape' characters to html entities or octal escapes or ...
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-20-2005 06:32 AM
тАО12-20-2005 06:32 AM
Re: PERL - Escape special characters
Yes, method-2 as you described where was I was (badly) trying to get toward :-)
/* no points please */
Regards (and thanks)!
...JRF...