Sponsored Content
Full Discussion: Perl script issue: print
Top Forums Shell Programming and Scripting Perl script issue: print Post 302323973 by man on Tuesday 9th of June 2009 01:22:51 PM
Old 06-09-2009
Perl script issue: print

Can someone tell me what I'm doing wrong with my perl script? I am new to Perl. This isn't even the final script, I'm just testing to see if it will print the directories with the files in it. For some reason my output is only printing the 1st, 6th, and last entries of the @sub_dir array. Each of the sub_dir folders has 4 test files in it (Test1-4.txt).

My intent is to ultimately copy multiple files from source to destination--since perl won't let me do it as easily as in shell. TIA Smilie

Code:
#!perl.exe

use strict;
use File::Copy;

my @sub_dir = ("sqr","src","user","nvision","winword","crw","excel","maint","projects","scripts","data");
my $source = "C:\\Test";
my $destination = "C:\\Test2";

foreach (@sub_dir) 
   {
   my $dir1 = glob($source . "\\" . $_ . "\\*");
   my $dir2 = glob($destination . "\\" . $_);
   
   print "$dir1\n";
   }


Here is my output:

C:\Scripts>perl refresh_test.pl
C:\Test\sqr\Test1.txt
C:\Test\sqr\Test2.txt
C:\Test\sqr\Test3.txt
C:\Test\sqr\Test4.txt

C:\Test\crw\Test1.txt
C:\Test\crw\Test2.txt
C:\Test\crw\Test3.txt
C:\Test\crw\Test4.txt

C:\Test\data\Test1.txt
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl - why is the shell script executed before the print command?

i'm writing some simple scripts to help me learn perl. why does the print command get called after the shell script is executed? the purpose of the shell script is to simply echo to the screen "script run". which is does, but before the print command, you can clearly see the shell script is... (3 Replies)
Discussion started by: mjays
3 Replies

2. Shell Programming and Scripting

Perl Script Issue - Please Help * Thanks!!!

Please help me with my script please. I am trying to do the following: 1. Read files for the current directory 2. Open and read from nbe files files only 3. Read only the lines with the results pattern 4. Split the line and print 3rd field Please indicate what line I need to modify. ... (8 Replies)
Discussion started by: jroberson
8 Replies

3. Shell Programming and Scripting

Perl Script issue. What am I doing wrong?

#!/usr/local/bin/perl open (MYFILE, 'logs_report'); while (<MYFILE>) { $rec=$_; chomp ($rec); @arr=split(/ /,$rec); print $rec,"\n" if ($arr!~/OK/); open (MYF, '>data.txt'); print $rec,"\n" if ($arr!~/OK/); close (MYF); (14 Replies)
Discussion started by: SkySmart
14 Replies

4. Shell Programming and Scripting

Perl Print Problems in script

Hi Perl Gurus, perl -e 'print "http://www.site@domain.com"' The output of the above is : http://www.site.com" I want to print http://www.site@domain.com without using escape sequence before '@' like '\@'. Is there any way to do this in perl? Thanks, Som (1 Reply)
Discussion started by: som.nitk
1 Replies

5. Shell Programming and Scripting

Perl Script - Print Content of next line

Good evening to you all perl experts I need your help I have a very simple script where I´m trying to print a line from status.dat file. The script will find the line containing "servicestatus", and I want to print the content of the next line. For example, the file contains this text:... (6 Replies)
Discussion started by: zarahel
6 Replies

6. Shell Programming and Scripting

how to print out data from mysql table in perl script

I'm having trouble with this code. if i do .\read.pl -u user it prints out 2010-12-20 12:00:00 host1 <cmd>a 2010-12-20 12:00:01 host1 <cmd> <execute> 2010-12-20 12:00:02 host1 <cmd>b 2010-12-20 12:00:03 host1 <cmd>c however, if i enter .\read.pl -h host1 it should... (3 Replies)
Discussion started by: kpddong
3 Replies

7. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

8. Shell Programming and Scripting

Perl script issue

Hi All, I have a perl script which I am using in Windows environment. There is one more file called "functions.txt" which is having all the functions defined to used in my perl script. And the path for this function file is defined in my perl script. Howeever sometimes I am getting below error... (4 Replies)
Discussion started by: gr8_usk
4 Replies

9. Shell Programming and Scripting

Issue regarding dos2unix perl script

Hi All, I have pearl script which will check and convert the file: INFO("dos2unix_cmds".$#{$dos2unix_cmds}); if ( $#{$dos2unix_cmds} == 0 ) { my $convert_cmd = $$dos2unix_cmds; my $rename_cmd = $$dos2unix_cmds; --conversion going here else INFO ("No need to... (8 Replies)
Discussion started by: saps19
8 Replies

10. Shell Programming and Scripting

perl script print the lines between two pattern

i have a file as below sample.pl parameter1 argument1 argument2 parameter2 I want out as below argument1 argument2 that is , i want to print all the lines between parameter1 & parameter 2. i tried with the following if($mystring =~ m/parameter1(.*?)parameter2/) (2 Replies)
Discussion started by: roopa
2 Replies
Test::Compile(3pm)					User Contributed Perl Documentation					Test::Compile(3pm)

NAME
Test::Compile - Check whether Perl module files compile correctly SYNOPSIS
#!perl -w use strict; use warnings; use Test::Compile; all_pm_files_ok(); DESCRIPTION
"Test::Compile" lets you check the validity of a Perl module file or Perl script file, and report its results in standard "Test::Simple" fashion. BEGIN { use Test::Compile tests => $num_tests; pm_file_ok($file, "Valid Perl module file"); } It's probably a good idea to run this in a BEGIN block. The examples below omit it for clarity. Module authors can include the following in a t/00_compile.t file and have "Test::Compile" automatically find and check all Perl module files in a module distribution: use Test::More; eval "use Test::Compile 0.09"; Test::More->builder->BAIL_OUT( "Test::Compile 0.09 required for testing compilation") if $@; all_pm_files_ok(); You can also specify a list of files to check, using the "all_pm_files()" function supplied: use strict; use Test::More; eval "use Test::Compile 0.09"; Test::More->builder->BAIL_OUT( "Test::Compile 0.09 required for testing compilation") if $@; my @pmdirs = qw(blib script); all_pm_files_ok(all_pm_files(@pmdirs)); Or even (if you're running under Apache::Test): use strict; use Test::More; eval "use Test::Compile 0.09"; Test::More->builder->BAIL_OUT( "Test::Compile 0.09 required for testing compilation") if $@; my @pmdirs = qw(blib script); use File::Spec::Functions qw(catdir updir); all_pm_files_ok( all_pm_files(map { catdir updir, $_ } @pmdirs) ); Why do the examples use "BAIL_OUT()" instead of "skip_all()"? Because testing whether a module compiles is important. "skip_all()" is ok to use with Test::Pod, because if the pod is malformed the program is still going to run. But checking whether a module even compiles is something else. Test::Compile should be mandatory, not optional. FUNCTIONS
"pm_file_ok(FILENAME[, TESTNAME ])" "pm_file_ok()" will okay the test if the Perl module compiles correctly. When it fails, "pm_file_ok()" will show any compilation errors as diagnostics. The optional second argument "TESTNAME" is the name of the test. If it is omitted, "pm_file_ok()" chooses a default test name "Compile test for FILENAME". "pl_file_ok(FILENAME[, TESTNAME ])" "pl_file_ok()" will okay the test if the Perl script compiles correctly. You need to give the path to the script relative to this distribution's base directory. So if you put your scripts in a 'top-level' directory called script the argument would be "script/filename". When it fails, "pl_file_ok()" will show any compilation errors as diagnostics. The optional second argument "TESTNAME" is the name of the test. If it is omitted, "pl_file_ok()" chooses a default test name "Compile test for FILENAME". "all_pm_files_ok([@files/@directories])" Checks all the files in @files for compilation. It runs all_pm_files() on each file/directory, and calls the "plan()" function for you (one test for each function), so you can't have already called "plan". If @files is empty or not passed, the function finds all Perl module files in the blib directory if it exists, or the lib directory if not. A Perl module file is one that ends with .pm. If you're testing a module, just make a t/00_compile.t: use Test::More; eval "use Test::Compile 0.09"; plan skip_all => "Test::Compile 0.09 required for testing compilation" if $@; all_pm_files_ok(); Returns true if all Perl module files are ok, or false if any fail. Or you could just let Module::Install::StandardTests do all the work for you. "all_pl_files_ok([@files])" Checks all the files in @files for compilation. It runs pl_file_ok() on each file, and calls the "plan()" function for you (one test for each file), so you can't have already called "plan". If @files is empty or not passed, the function uses all_pl_files() to find scripts to test If you're testing a module, just make a t/00_compile_scripts.t: use Test::More; eval "use Test::Compile 0.09"; plan skip_all => "Test::Compile 0.09 required for testing compilation" if $@; all_pl_files_ok(); Returns true if all Perl module files are ok, or false if any fail. "all_pm_files([@dirs])" Returns a list of all the perl module files - that is, files ending in .pm - in $dir and in directories below. If no directories are passed, it defaults to blib if blib exists, or else lib if not. Skips any files in "CVS" or ".svn" directories. The order of the files returned is machine-dependent. If you want them sorted, you'll have to sort them yourself. "all_pl_files([@files/@dirs])" Returns a list of all the perl script files - that is, files ending in .pl or with no extension. Directory arguments are searched recursively . If arguments are passed, it defaults to script if script exists, or else bin if bin exists. Skips any files in "CVS" or ".svn" directories. The order of the files returned is machine-dependent. If you want them sorted, you'll have to sort them yourself. AUTHORS
Sagar R. Shah "<srshah@cpan.org>", Marcel Gruenauer, "<marcel@cpan.org>", Evan Giles, "<egiles@cpan.org>" COPYRIGHT AND LICENSE
Copyright 2007-2012 by the authors. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Test::LoadAllModules just handles modules, not script files, but has more fine-grained control. perl v5.14.2 2012-02-27 Test::Compile(3pm)
All times are GMT -4. The time now is 02:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy