RE: Recovered windows files and dos name limitations -- Ideas?

2001-05-13 Thread King, Jason

Matt Cauthorn writes ..

>A friend of mine just had a drive crash on him. He was able to save
>some of the files in dos, as his win98 couln't boot. Now all of his
>mp3s have the dos 8 character limit on them, but winamp in his new
>win98 can actually read the long version of the name on 80% of them.
>
>This tells me there must be a way to write a script that will read the
>long file name and re-name it using VFAT or whatever win file system
>type supports long file names. There are simply too many of them to
>just rename by hand! Any ideas or modules you can suggest?


MP3s have special information stored in the file (called a ID3 Tag) this can
store (amongst other things) something that might look like the long
filename of an MP3

but files other than MP3 have no such information built into them .. Win98
stores that long filename information elsewhere .. so if the files have gone
via DOS - then the long filename information is lost forever

if you want to rename just the MP3s then take a look at CPAN for MP3::Info

and you'll also want to use the File::Find module (it's part of the core
distribution) to drill down through the directories

references:

  http://search.cpan.org/search?dist=MP3-Info
  perldoc File::Find
  perldoc -f rename

-- 
  jason king

  By South Carolina state law, if a man promises to marry an unmarried
  woman, the marriage must take place. - http://dumblaws.com/



RE: CR LF with UNIX and Windows (DOSish?)

2001-05-13 Thread King, Jason

David Falck writes ..


>Is there a programmatic way to tell if I'm on Windows or UNIX? I know
>that $^0 returns the name of the operating system, but can I count on
>matching /MS/i or /Win/i to determine if it's Windows?> If Windows,
>I'll assign 2 to $newline below, else I'll assign 1.


it completely depends on the build process of that version of Perl .. I
think that Cygwin has a different string than the standard (ActiveState)
build

for ActiveState's Perl build it is guranteed to literally match 'MSWin32' on
all Microsoft Win32 platforms .. these are currently

  Windows95
  Windows98
  WindowsMe
  WindowsNT 3.51
  WindowsNT 4.0
  Windows2000

and will soon include

  WindowsXP

hence your code (assuming ActiveState Perl) would be

  my $newline = ( $^O eq 'MSWin32' ? 2 : 1 );

but check to see what the Cygwin build produces (using perl -V and looking
at the osname value)


references:

  perldoc perlvar | grep -A10 "$OSNAME"
  perl -V | grep "osname"

-- 
  jason king

  By South Carolina state law, if a man promises to marry an unmarried
  woman, the marriage must take place. - http://dumblaws.com/



Re: CR LF with UNIX and Windows (DOSish?)

2001-05-13 Thread Mike Lacey

Missed the fact that you are using seek, sorry.

Don't know about the consistency of $^O, WinME returns "MSWin32" if that's
any help to you.

Mike

- Original Message -
From: "David Falck" <[EMAIL PROTECTED]>
To: "Mike Lacey" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, May 14, 2001 2:46 AM
Subject: RE: CR LF with UNIX and Windows (DOSish?)


> Mike,
>
> Thanks for your response. Yes, Perl knows which system it's on, and
because
> of this I have no problem when writing the record. But because I'm doing a
> seek when reading the record I have to account for every byte in my
> algorithm below. So I thought my solution would be to determine the
> operating system.
>
> My concern is - does Windows always include MS or Win in the name of ALL
> their operating systems, so I can match $^0 against those values?
>
> Thanks,
> David
>
> -Original Message-
> From: Mike Lacey [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, May 13, 2001 9:26 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: CR LF with UNIX and Windows (DOSish?)
>
>
> David,
>
> My understanding is that you don't need to worry about what character(s)
> contitute a newline. The different versions of Perl know about this and do
> what you would expect.
>
> So \n on UNIX is a LF and CRLF on DOS.
>
> Did you already try this and encounter problems?
>
> Mike
> ---
> Mike Lacey
>
> www.tek-tips.com -- a friendly, flame free, environment for computer
> professionals and students
> Perl forum at:
> http://www.tek-tips.com/gthreadminder.cfm/lev2/4/lev3/32/pid/219
>
>
> - Original Message -
> From: "David Falck" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, May 14, 2001 2:15 AM
> Subject: CR LF with UNIX and Windows (DOSish?)
>
>
> > Is there a programmatic way to tell if I'm on Windows or UNIX? I know
that
> > $^0 returns the name of the operating system, but can I count on
matching
> > /MS/i or /Win/i to determine if it's Windows? If Windows, I'll assign 2
to
> > $newline below, else I'll assign 1.
> >
> > Problem:
> > I have a fixed length customer record. When I create the record, I add
\n.
> > But my testing tells me that when I read (seek) the record below, I have
> to
> > add 2 for Windows or 1 for UNIX.
> >
> > # Customer file data  -
> > $cst_template =
> > "A9A15A15A1A30A30A30A30A9A2A13A40A13A5A2A16A2A2A1A1A10A10A10A7";
> > $cst_rec_len = 303;   # sum all customer fields
> > $newline = 2; # changes based on OS
> > $cst_offset = $cst_rec_len + $newline;
> >
> > # reading the customer record
> > seek(CSTMST, ($rec_nbr * $cst_offset), 0) # $rec_nbr is the physical
> record
> > number
> >
> > Solution:
> > Remove the hard coding above for $newline. Then assign 2 to $newline if
> > Windows, else assign 1 to $newline. But do I look at $^0 to determine
the
> > operating system, or is there a better way?
> >
> > Thanks,
> > David
> >
>
>




RE: CR LF with UNIX and Windows (DOSish?)

2001-05-13 Thread David Falck

Mike,

Thanks for your response. Yes, Perl knows which system it's on, and because
of this I have no problem when writing the record. But because I'm doing a
seek when reading the record I have to account for every byte in my
algorithm below. So I thought my solution would be to determine the
operating system.

My concern is - does Windows always include MS or Win in the name of ALL
their operating systems, so I can match $^0 against those values?

Thanks,
David

-Original Message-
From: Mike Lacey [mailto:[EMAIL PROTECTED]]
Sent: Sunday, May 13, 2001 9:26 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: CR LF with UNIX and Windows (DOSish?)


David,

My understanding is that you don't need to worry about what character(s)
contitute a newline. The different versions of Perl know about this and do
what you would expect.

So \n on UNIX is a LF and CRLF on DOS.

Did you already try this and encounter problems?

Mike
---
Mike Lacey

www.tek-tips.com -- a friendly, flame free, environment for computer
professionals and students
Perl forum at:
http://www.tek-tips.com/gthreadminder.cfm/lev2/4/lev3/32/pid/219


- Original Message -
From: "David Falck" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 14, 2001 2:15 AM
Subject: CR LF with UNIX and Windows (DOSish?)


> Is there a programmatic way to tell if I'm on Windows or UNIX? I know that
> $^0 returns the name of the operating system, but can I count on matching
> /MS/i or /Win/i to determine if it's Windows? If Windows, I'll assign 2 to
> $newline below, else I'll assign 1.
>
> Problem:
> I have a fixed length customer record. When I create the record, I add \n.
> But my testing tells me that when I read (seek) the record below, I have
to
> add 2 for Windows or 1 for UNIX.
>
> # Customer file data  -
> $cst_template =
> "A9A15A15A1A30A30A30A30A9A2A13A40A13A5A2A16A2A2A1A1A10A10A10A7";
> $cst_rec_len = 303;   # sum all customer fields
> $newline = 2; # changes based on OS
> $cst_offset = $cst_rec_len + $newline;
>
> # reading the customer record
> seek(CSTMST, ($rec_nbr * $cst_offset), 0) # $rec_nbr is the physical
record
> number
>
> Solution:
> Remove the hard coding above for $newline. Then assign 2 to $newline if
> Windows, else assign 1 to $newline. But do I look at $^0 to determine the
> operating system, or is there a better way?
>
> Thanks,
> David
>





Re: CR LF with UNIX and Windows (DOSish?)

2001-05-13 Thread Mike Lacey

David,

My understanding is that you don't need to worry about what character(s)
contitute a newline. The different versions of Perl know about this and do
what you would expect.

So \n on UNIX is a LF and CRLF on DOS.

Did you already try this and encounter problems?

Mike
---
Mike Lacey

www.tek-tips.com -- a friendly, flame free, environment for computer
professionals and students
Perl forum at:
http://www.tek-tips.com/gthreadminder.cfm/lev2/4/lev3/32/pid/219


- Original Message -
From: "David Falck" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 14, 2001 2:15 AM
Subject: CR LF with UNIX and Windows (DOSish?)


> Is there a programmatic way to tell if I'm on Windows or UNIX? I know that
> $^0 returns the name of the operating system, but can I count on matching
> /MS/i or /Win/i to determine if it's Windows? If Windows, I'll assign 2 to
> $newline below, else I'll assign 1.
>
> Problem:
> I have a fixed length customer record. When I create the record, I add \n.
> But my testing tells me that when I read (seek) the record below, I have
to
> add 2 for Windows or 1 for UNIX.
>
> # Customer file data  -
> $cst_template =
> "A9A15A15A1A30A30A30A30A9A2A13A40A13A5A2A16A2A2A1A1A10A10A10A7";
> $cst_rec_len = 303;   # sum all customer fields
> $newline = 2; # changes based on OS
> $cst_offset = $cst_rec_len + $newline;
>
> # reading the customer record
> seek(CSTMST, ($rec_nbr * $cst_offset), 0) # $rec_nbr is the physical
record
> number
>
> Solution:
> Remove the hard coding above for $newline. Then assign 2 to $newline if
> Windows, else assign 1 to $newline. But do I look at $^0 to determine the
> operating system, or is there a better way?
>
> Thanks,
> David
>




CR LF with UNIX and Windows (DOSish?)

2001-05-13 Thread David Falck

Is there a programmatic way to tell if I'm on Windows or UNIX? I know that
$^0 returns the name of the operating system, but can I count on matching
/MS/i or /Win/i to determine if it's Windows? If Windows, I'll assign 2 to
$newline below, else I'll assign 1.

Problem:
I have a fixed length customer record. When I create the record, I add \n.
But my testing tells me that when I read (seek) the record below, I have to
add 2 for Windows or 1 for UNIX.

# Customer file data  -
$cst_template =
"A9A15A15A1A30A30A30A30A9A2A13A40A13A5A2A16A2A2A1A1A10A10A10A7";
$cst_rec_len = 303;   # sum all customer fields
$newline = 2; # changes based on OS
$cst_offset = $cst_rec_len + $newline;

# reading the customer record
seek(CSTMST, ($rec_nbr * $cst_offset), 0) # $rec_nbr is the physical record
number

Solution:
Remove the hard coding above for $newline. Then assign 2 to $newline if
Windows, else assign 1 to $newline. But do I look at $^0 to determine the
operating system, or is there a better way?

Thanks,
David




Re: Sorting a file

2001-05-13 Thread Jeff Pinyan

On May 13, Jeff Pinyan said:

>if (/(?:^|\@)(\S+)/) {

I had a precedence error in my code here.  That regex will match at the
beginning of the line every time.  It should be:

  if (/\@(\S+)/ or /(\S+)/) {
# ...
  }

Sigh.  And I'm writing a book about these.  I should get my act
together. ;)

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734




Re: Sorting a file

2001-05-13 Thread Jeff Pinyan

On May 13, Thomas Leuxner said:

>#mydomain.com
>mydomain.com   anything
>[EMAIL PROTECTED]   tlx
>

>#newdomain.com
>newdomain.com  anything
>
>
>#somewhere.com
>somewhere.com  anything
>

I suggest you make a hash of array references.  The keys of the hash will
be the comment lines -- more specifically, the domains mentioned
there.  The values in the hash will be array references of the lines for
that domain.

  my $file = "...";
  my %records;

  open FILE, "+< $file" or die "can't r/w $file: $!";

  while () {
next if /^#?$/;  # skip empty lines and comment lines

# append to the list of records for a given domain
if (/(?:^|\@)(\S+)/) {
  push @{ $records{$1} }, $_;
}
  }

  # rewind file
  seek FILE, 0, 0;  

  # truncate file to 0 bytes
  truncate FILE, 0;

  # spit information out in readable form
  for (sort keys %records) {
print FILE "#$_\n", @{ $records{$_} }, "\n";
  }

  close FILE;

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734




Sorting a file

2001-05-13 Thread Thomas Leuxner

Hi,
i'm currently writing a configuration tool for postfix virtual tables. Right 
now each new mailalias/account is appended to the postfix "virtual"-file, 
which works fine. There are checks if there is already a domain-placeholder 
like "#mydomain.com" in that file, if not one is appended plus a 
"mydomain.com anything" entry. Afterwards the mailalias is appended.

example file:
#mydomain.com
mydomain.comanything
[EMAIL PROTECTED]tlx


Since everything is appended to the file, it easily turns human-unreadable. 
E-mail addresses for a single domain are spread all over the file. It lacks a 
sorting like:

#newdomain.com
newdomain.com   anything


#somewhere.com
somewhere.com   anything


Can this be accomplished via a sort-routine or should i change the way values 
are written to that file?
Any help is appreciated

Thanks Thomas Leuxner