how to create a file in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create a file in perl
# 1  
Old 05-02-2010
how to create a file in perl

hey gurus!

i m a perl newbie!!

i want to create an empty file and also directory in perl...

how to print a msg if the present working directory has ".db" extension. like in shell

Code:
if [[ "$PWD" = *.db ]] ; then
          echo "hello "

i want to do this in perl!!
please help..
# 2  
Old 05-02-2010
HI,

Try this,

Below code is to create empty file.
Code:
open(FW,">/root/ps.txt");
print FW "";

below code is to match directory name end with ".db"
Code:
if ( $wrkdir =~ /.*\.db$/ ) { print "hellow\n"; }

# 3  
Old 05-02-2010
MySQL

thanks very much pravin!!

it worked Smilie
# 4  
Old 05-02-2010
Quote:
Originally Posted by pravin27
HI,

Try this,

Below code is to create empty file.
Code:
open(FW,">/root/ps.txt");
print FW "";

below code is to match directory name end with ".db"
Code:
if ( $wrkdir =~ /.*\.db$/ ) { print "hellow\n"; }

use 3 argument style and failure condition handling as well
Code:
my $lfh;
open($lfh, '>', $filename) or
die "Unable to open file $filename : $!";
close($lfh) or die "Unable to close file : $filename $!";

# 5  
Old 05-02-2010
thanks matrixmadhan!!!..

i've got anather problem ...

how can i actually switch to another directory with "chdir" in perl.

like the we used to do is bash as:

Code:
$cat abc
cd Desktop/

...

Code:
  $source ./abc    // or . ./abc

this will change our current working directory.

how can do this with perl..that can actually change our current directory..

please help!!

thanx!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using perl or awk to create ngrams

Hello, I am interested in writing a context driven NGram analysis i.e. detecting the frequency of utterance of a given character based on its immediate context i.e. the character which can preced and follow the given entity. In the case of Intial and Final the context would be immediate character... (4 Replies)
Discussion started by: gimley
4 Replies

2. Programming

help need in the perl script that create one xml file form multiple files.

Hi every one, Please excuse me if any grammatical mistakes is there. I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p> file1:bvr.xml ... (0 Replies)
Discussion started by: veerubiji
0 Replies

3. Programming

perl script to create hash.

Hi, I have the xml file file this, perl script to create hash<p> <university> <name>svu</name> <location>ravru</location> <branch> <electronics> <student name="xxx" number="12"> <semester number="1"subjects="7" rank="2"/> </student> <student name="xxx"... (1 Reply)
Discussion started by: veerubiji
1 Replies

4. Shell Programming and Scripting

How to create hash dynamically in perl?

Hi, I have one file name file.txt It has the following contents: #File Contents StartTime,EndTime,COUNTER1,COUNTER2,COUNTER3 12:13,12:14,0,1,0 The output should be like this: StartTime: 12:13 ENDTIME: 12:14 (2 Replies)
Discussion started by: vanitham
2 Replies

5. Shell Programming and Scripting

How to create a xml file using Perl Script

Hi All, I have some data which needs to be saved in the xml file format.Can you guys please let me know how to do this using perl script. NOTE: the template of the xml file shall be depending on validation of the data done for some requirements. Basically to summarise, the fields in the xml... (5 Replies)
Discussion started by: girish.raos
5 Replies

6. Shell Programming and Scripting

Create tab-delimited file of outputs - Perl

Title is very broad, but here's an outline of what I have done so far: - I have multiple subdirectories containing multiple *.fna files of DNA sequences - I've been able to traverse these subdirectories and create a tab-delimited text file (i.e. the association file) that shows the contents of... (1 Reply)
Discussion started by: shwang3
1 Replies

7. Shell Programming and Scripting

I need help to create a file using Perl

Hi, i have some files in text format and i want to create a file with all the information in the others files, but i don't want copy all the information exactly i just need the information from the fourth line to the end of file I will try to explain with an example: file1.txt abc abc... (1 Reply)
Discussion started by: romanhr
1 Replies

8. AIX

create widgets using perl pk module

hi I am posting this for my friend... is it possible to create widgets using perl pk module in IBM AIX 5.3? They dont have a GUI so is it possible to create the above mentioned thing in a CUI? thanks! Sathish (1 Reply)
Discussion started by: sathumenon
1 Replies

9. Shell Programming and Scripting

create an user in perl

hi friends, i want to create an new user in my home directory , only just for checking. if it is possible, please help me. thanks (1 Reply)
Discussion started by: praneshbmishra
1 Replies

10. Shell Programming and Scripting

create a directory in perl

Hi Guys!!!!!!!!!!!!!!!!!!!!! can we create or copy directories in perl without using system commands like "mkdir" and "cp" script needed urgent !!!!!!!!!!!!!!!!!!!!!!!!!!! cheers, aajan (7 Replies)
Discussion started by: aajan
7 Replies
Login or Register to Ask a Question