Sponsored Content
Top Forums Shell Programming and Scripting Print the current directory using perl Post 302514853 by srijith on Monday 18th of April 2011 09:36:37 AM
Old 04-18-2011
Print the current directory using perl

Hi I have this code to print the current directory using Perl

Code:
use Cwd qw(abs_path);
my $path = abs_path($0);
print "$path\n";

But it is displaying my perl source code file along with the directory.

like this

C:\Perl\duration.pl


But I want it only to display this "C:\Perl\"

Any clues ? I know this is a easy one. But I am a newbie..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Run perl script in the current process

I have a question regarding running perl in the current process. I shall demonstrate with an example. Look at this. sh-2.05b$ pwd /tmp sh-2.05b$ cat test.sh #! /bin/sh cd /etc sh-2.05b$ ./test.sh sh-2.05b$ pwd /tmp sh-2.05b$ . ./test.sh sh-2.05b$ pwd /etc sh-2.05b$ So... (10 Replies)
Discussion started by: vino
10 Replies

2. Shell Programming and Scripting

How to print current month - 1 in string format

I need to get the current month -1 in string format, like Feb-2006. I am using k shell. Any help is appreciated. (3 Replies)
Discussion started by: mogli4
3 Replies

3. UNIX for Dummies Questions & Answers

awk to print current date?

List, I want to print the first line of my text file (say "me you"), preceded by the current date/time. Something like (pseudo code): awk '{print date,$1}' I don't have a lot of awk knowledge (understatement), so forgive me if the answer is obvious... (3 Replies)
Discussion started by: philipz
3 Replies

4. Shell Programming and Scripting

Print previous, current and next line using sed

Hi, how can i print the previous, current and next line using sed? current line is the matching line. The following prints all lines containing 'Failure' and also the immediate next line cat $file | sed -n -e '/Failure/{N;p;}' Now, i also want to print the previous line too. Thanks,... (8 Replies)
Discussion started by: ysrinu
8 Replies

5. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

6. Shell Programming and Scripting

Print the name of files in the directory using Perl

Hi All, I am stuck with a problem and i want your help, what i want to do is I have a directory name dircome and there are 6 files present in this directory, the name of the files are d1,d2,d3,d4,d5,d6. The Perl script print the files name, means the output should be d1 d2 d3 d4 d5 d6 (9 Replies)
Discussion started by: parthmittal2007
9 Replies

7. UNIX for Dummies Questions & Answers

Current working directory

Hi all, How do I print the name of my current working directory only to screen? Not pwd! For example, if I was in /home/work I am looking for 'work' only (4 Replies)
Discussion started by: jimjam
4 Replies

8. Shell Programming and Scripting

Compare between current and next line and print

Dear All I want below to compare two Consecutive line(i.e. current and next line). Based in that i need OP. Below is the IP file in that in i find "M" and if in next line i find "*" then i need both line in single line. If i dont find "*" in next line then i need to put commend "DOWN" . I am... (4 Replies)
Discussion started by: jaydeep_sadaria
4 Replies

9. Shell Programming and Scripting

Tput cup, print on current line?

Heyas I'm thinking about a new approach for my core display, basicly as it should make aligments easier. Issue i'm currently facing, is tput cup capable of printing on the current line? My best achievements were: :) tui $ tput cup - 60;echo " ------ testing" ------ testing... (5 Replies)
Discussion started by: sea
5 Replies

10. UNIX for Beginners Questions & Answers

Print out my current http connection

Good evening Need you help please I just wanna to print out my current https connection and other users http connection which the application resides, for instance i connect to the below url to login into the application: https://serverappp01:14100/portal/Portal.html# In another session... (4 Replies)
Discussion started by: alexcol
4 Replies
File::Spec::Link(3pm)					User Contributed Perl Documentation				     File::Spec::Link(3pm)

NAME
File::Spec::Link - Perl extension for reading and resolving symbolic links SYNOPSIS
use File::Spec::Link; my $file = File::Spec::Link->linked($link); my $file = File::Spec::Link->resolve($link); my $dirname = File::Spec::Link->chopfile($file); my $newname = File::Spec::Link->relative_to_file($path, $link); my $realname = File::Spec::Link->full_resolve($file); my $realname = File::Spec::Link->resolve_path($file); my $realname = File::Spec::Link->resolve_all($file); DESCRIPTION
"File::Spec::Link" is an extension to "File::Spec", adding methods for resolving symbolic links; it was created to implement "File::Copy::Link". "linked($link)" Returns the filename linked to by $link: by "readlink"ing $link, and resolving that path relative to the directory of $link. "resolve($link)" Returns the non-link ultimately linked to by $link, by repeatedly calling "linked". Returns "undef" if the link can not be resolved. "chopfile($file)" Returns the directory of $file, by splitting the path of $file and returning (the volumne and) directory parts. "relative_to_file($path, $file)" Returns the path of $path relative to the directory of file $file. If $path is absolute, just returns $path. "resolve_all($file)" Returns the filename of $file with all links in the path resolved, wihout using "Cwd". "full_resolve($file)" Returns the filename of $file with all links in the path resolved. This sub tries to use "Cwd::abs_path" via "->resolve_path". "resolve_path($file)" Returns the filename of $file with all links in the path resolved. This sub uses "Cwd::abs_path" and is independent of the rest of "File::Spec::Link". Object methods "new([$path])" create new path object: stores path as a list "path" returns path as a string, using catpath "canonical" returns canonical path, using canonpath "vol" returns volume element of path, see File::Spec->splitpath "dir" returns directory element of path, as a string, see File::Spec->splitpath "dirs" return list of directory components in path, see File::Spec->splitdir "pop" remove last component of the path "push($file)" add a file component to the path, ignoring empty strings "add($file)" add a component to the path: treating "updir" as "pop", and ignoring "curdir" and empty strings "split($path)" populate a path object, using splitpath "chop" remove and return a file component from path, an empty string returns means this was root dir. "relative($path)" replace the path object with the supplied path, where the new path is relative to the path object "follow" follow the link, where the path object is a link "resolved" resolve the path object, by repeatedly following links "resolvedir" resolve the links at all component levels within the path object Other class methods "canonpath($path)" Wrapper round File::Spec::canonpath, fatal if empty input "catdir(@dirs)" Wrapper round File::Spec::catdir, returns "curdir" from empty list "splitlast($path)" Get component from $path (using "chop") and returns remaining path and compenent, as strings. [Not used] EXPORT None - all subs are methods for "File::Spec::Link". SEE ALSO
File::Spec(3) File::Copy::Link(3) AUTHOR
Robin Barker, <Robin.Barker@npl.co.uk> COPYRIGHT AND LICENSE
Copyright 2003, 2005, 2006, 2007 by Robin Barker This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-09-30 File::Spec::Link(3pm)
All times are GMT -4. The time now is 07:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy