Sponsored Content
Full Discussion: Shift Question (Perl)
Top Forums Shell Programming and Scripting Shift Question (Perl) Post 302274529 by ifeatu on Wednesday 7th of January 2009 09:08:17 PM
Old 01-07-2009
help

Okay I'm getting a syntax error here is my code

Code:
open(FILE, "test2.txt") or die ("The file is not found");

$citymap = ( UC => "Union City", VJ => "Vallejo", Vallejo => "Vallejo", Union Ci
ty => "Union City", berk => "Berkeley", Berk => "Berkeley" );
$month2int  = ( Jan => 1, Feb => 2, Mar => 3, mar => 3, March => 3, Apr => 4, ap
r => 4, April => 4, may => 5, May => 5, Jun => 6, Jul => 7, July => 7, jul => 7,
 aug => 8, Aug => 8, August => 8, august => 8, Sept => 9, September => 9, sept =
> 9,Okt => 10, Oct => 10, October => 10, oct => 10, nov => 11, Nov => 11, Novemb
er => 11, november => 11, Dec => 12, December => 12, december => 12);

while (<FILE>) {
($city,$year,$month,$day,$title,$speaker)=split('-');
$month=exists $month2int{$month} ? $month2int{$month} : $month;
$city=exists $citymap{$city} ? $citymap{$city} : ucfirst($city);
print join("-",$city,$year,$month,$day,$title,$speaker);
}

I run the command:
Code:
perl ConvertingFileNames

and my error is:

Code:
syntax error at ConvertingFileNames line 3, near "Union City"
Execution of ConvertingFileNames aborted due to compilation errors.

I noticed in the code you gave me you had a prefix of "%" instead of "$" for the variables defining the month and Location...I tried running with both and it gives me the same error

So I like to talk my code out in words correct me if I'm wrong here but this is what I have so far:

1. Open the file with the file names
2. Define variables to compare the file to
3. While not eof take each line of the file and split it by "-" and put each split value into a unique variable
4. Check two of the variables (month and location) against the two variables defined before the "while" statement
5. make the appropriate changes or do nothing if nothing matches
6. print each line of the file back in the same order it was found with the appropriate changes
7. Close file

Can you help me with syntax?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

shift command

There is an error when i am trying to use the shift command in this way: ($1 = -d, $2 = 123, $3 = -c etc etc) for $arg in $@ do case $arg in "-d") shift; (so that the $2 will become the $arg now) (and while it loop the 2nd time,) ... (1 Reply)
Discussion started by: AkumaTay
1 Replies

2. Shell Programming and Scripting

shift command

Hi Folks, In shell scripting the maximum no. of command line parameters becomes 9(Am i right). If we want to get more than 9 parameters we use the shift command. Even here there are two possibilities. 1. Without the use of variables - The arguments are lost and the lost no. is equal to the... (6 Replies)
Discussion started by: Nisha
6 Replies

3. Shell Programming and Scripting

Regarding the shift command???

I am running a program where in I have this command which is giving error the shift: number is not correct. can you please tell me how shift actually works? the line which is giving error is- set $PARAM; shift; shift; shift; shift; shift; shift; shift; shift Is it related somewhere to... (2 Replies)
Discussion started by: shrao
2 Replies

4. Shell Programming and Scripting

shift and push question in perl

hi, another perl question, I don't understand the below while (<FILE>) { push @last5, $_; #add to the end shift @last5 if @last5 > 5 ; #take from the beginning } can someone please explain to me how does shift @last5 if @last5 > 5 is taking last 5 lines from... (5 Replies)
Discussion started by: hankooknara
5 Replies

5. UNIX for Dummies Questions & Answers

shift not working

Hi, I wrote one script, in between script needs to use 10th and 11th positional parameters, that time i used "shift". Here i am facing the below find problem, ./DataCount.sh: cannot shift I tried 1) I have read man pages for shift 2) Before but * and ** 3) Simple shift with out giving... (4 Replies)
Discussion started by: Nagapandi
4 Replies

6. Shell Programming and Scripting

script assistance with shift J

Hey all, I need some assistance. I'm writing a script to eject tapes from a tape library, but the library is not a queued system and can only eject 15 tapes at a time. I added paste -d : -s so that it goes through full_tapes and puts each media_id on one line separated by the :. Now I'm... (2 Replies)
Discussion started by: em23
2 Replies

7. UNIX for Dummies Questions & Answers

A Shift into UNIX

Hi, Firstly, I did a search for this question both on this site and on the internet and have not been able to find a suitable answer that is not general in nature. I have always been a Windows user. I use my girl friend's mac every now and then, but I always come back to windows. For a... (1 Reply)
Discussion started by: mearex
1 Replies

8. Shell Programming and Scripting

Use of Shift command

Hello Expert Can any one please explain what is the use of shift command in general terms: set -- $(ls -t) shift rm -Rf $* what is the use of shift command over here. Thanks a lot for your help (2 Replies)
Discussion started by: aks_1902
2 Replies

9. Homework & Coursework Questions

Need help with a Perl Script using Pop, Shift, & Push

Hello everyone, I am new to Perl and I am having some issues getting a script to work. I have to create a script that uses an array of 52 cards, "shuffles" the cards (using loops with the pop, shift, and push commands), and prints out the top five. This is not a randomizing of the array just a... (2 Replies)
Discussion started by: Hax0rc1ph3r
2 Replies

10. Shell Programming and Scripting

Shift command help

#!/bin/bash hostname=$1; shift for hostname in $1 do ping $hostname done I want to run the above script as hostname.sh yahoo.com google.com cnn.com. I want to shift each hostname to $1. How can do that with above code as currently it's not shifting. (5 Replies)
Discussion started by: scj2012
5 Replies
CAL(1)							    BSD General Commands Manual 						    CAL(1)

NAME
cal -- displays a calendar SYNOPSIS
cal [-smjy13] [[month] year] DESCRIPTION
Cal displays a simple calendar. If arguments are not specified, the current month is displayed. The options are as follows: -1 Display single month output. (This is the default.) -3 Display prev/current/next month output. -s Display Sunday as the first day of the week. (This is the default.) -m Display Monday as the first day of the week. -j Display Julian dates (days one-based, numbered from January 1). -y Display a calendar for the current year. A single parameter specifies the year (1 - 9999) to be displayed; note the year must be fully specified: ``cal 89'' will not display a calen- dar for 1989. Two parameters denote the month (1 - 12) and year. If no parameters are specified, the current month's calendar is displayed. A year starts on Jan 1. The Gregorian Reformation is assumed to have occurred in 1752 on the 3rd of September. By this time, most countries had recognized the ref- ormation (although a few did not recognize it until the early 1900's.) Ten days following that date were eliminated by the reformation, so the calendar for that month is a bit unusual. HISTORY
A cal command appeared in Version 6 AT&T UNIX. OTHER VERSIONS
Several much more elaborate versions of this program exist, with support for colors, holidays, birthdays, reminders and appointments, etc. For example, try the cal from http://home.sprynet.com/~cbagwell/projects.html or GNU gcal. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 10:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy