LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-24-2014, 12:43 AM   #1
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Rep: Reputation: Disabled
Perl equivalent of unix2dos


I want to know the perl equivalent of unix2dos function.

I am using a unix command in my perl program , i want to replace it with perl equivalent. Please suggest if any
 
Old 12-24-2014, 01:21 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Code:
    system("unix2dos ".$file);
where $file contains the filename.

A quick search turned up this answer and I'm sure there are many more. You might want to get into the habit of doing a search for an answer yourself. It will save you loads of time and make you feel better when you find one. I found the solution given above here.
jdk
 
Old 12-24-2014, 01:43 AM   #3
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Original Poster
Rep: Reputation: Disabled
I am already using system command , searched through internet. I want to use perl equivalent of unix2dos , so that my program should work in unix as well as windows.
 
Old 12-24-2014, 02:35 AM   #4
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
A quick search turned up another solution. Since you know exactly what you want and I am not a mind-reader if you're not happy with this solution then I'd strongly suggest you do a search yourself.
http://www.perlmonks.org/?node_id=368336
jdk
 
Old 12-24-2014, 03:46 AM   #5
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Original Poster
Rep: Reputation: Disabled
Yes I am doing the search, dont worry u are not the only one in LQ, there are others too.

Thanks for your time.
 
Old 12-24-2014, 05:08 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,129

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
yes, the link contained the following solution: perl -i.bak -pe 's/\012/\015\012/g' infile
(do not use system call in perl if not required)
but I do not think this is the right way to make a program runnable on both unix and linux. What language is it at all?
In general using an editor you may try to specify unix or dos mode (to save that file).
 
Old 12-24-2014, 06:08 AM   #7
jags1984
Member
 
Registered: Mar 2013
Posts: 83

Original Poster
Rep: Reputation: Disabled
I am doing perl programming and dont want to use any system calls (backticks or system command) . I want to convert the log generated in windows format . So I was looking for a equivalent Unix2Dos command in perl.
 
Old 12-26-2014, 11:58 PM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
It really depends on what you actually are trying to do.

The command "perl -i.bak -pe 's/\012/\015\012/g'" is a perl command line to translate the <lf><ret> sequence (basically replacing it with <lf>). If perl is installed, then it should work the same on any UNIX like system.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
procedural equivalent of OOP in Perl electronpusher Programming 1 11-20-2012 03:58 PM
Perl equivalent of shell for & listener Programming 2 03-26-2010 11:37 AM
bash equivalent of <perl -e 'print time'> teabag_46 Linux - Newbie 2 10-23-2007 04:04 PM
The perl equivalent... Ateo Programming 4 04-09-2005 03:23 AM
unix2dos not found Big Al Slackware 4 07-19-2004 04:25 PM


All times are GMT -5. The time now is 08:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration