Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:30:33+00:00 2026-05-30T07:30:33+00:00

Hello stackpeople! I have 2 things to solve and display the results online in

  • 0

Hello stackpeople!

I have 2 things to solve and display the results online in a cgi-file.

A) get all foldernames at a given path

B) determine the age of the index.html inside each folder

the result should look like this:

[Number] [Foldername] [fileage]

This cgi-page runs on a solaris server with installed perl 5.8.4

My solution is a combination of bash and perl. To solve problem A) (the folder names) I have written a bash script:

#!/bin/bash
#
find /test/ -type d | sed -e 's/^.*\///'

This gives me a nice list of all foldernames in /test/

Now the perl code to show this output in a browser:

  #Establish a pipeline between the bash and my script.
  my $bash_command = '/test./foldernames.bash';
  open(my $pipe, '-|', $bash_command) or die "Can't open pipe: $!";
  # initialize variables
   my $foldername = "";
   my $i    = 0;

  # Process the output from bash command line by line.
  while (my $line = <$pipe>)
  {
   $foldername = $line;
   $i = $i+1;

   print"  <tr><td>$i</td><td>$foldername</td></tr>";
 }#end while

This works! I’ll get a nice table with [Number] and [Foldername] ! Now comes the tricky part! In addition, I want the date of an index.html located in each folder. Therefore I have another bash script:

ls -ltr /test/folder1/*.html | tail -1 | awk '{printf"%3s %1s %s\n",$6, $7, $8}`

This gives me the perfect output: Feb 22 10:56 Now I need this information in my table. I have added this line in my perl script within the while loop:

$timestamp = `ls -ltr /test/folder1/*.html | tail -1 | awk '{printf"%3s %1s %s\\n",\$6, \$7, \$8}`;

This works perfect when I add the foldername as a string. As soon as I exchange folder1 with $foldername I’ll get nonsense “ls” information.

Why is that so?

Edit: Now I have used:

use File::stat;
use Time::localtime;
my $timestamp = ctime(stat("/test/folder1")->mtime);

This is way more secure compared to parsing the ls output. But still I have issues with the $foldername. I have used the length function to determine the length of $Foldername.

$foldername has a length of 7, but the string output has only 6 chars: tomato

So I’ve tried Chop/chomp the $foldername with always the same result: 7 chars!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:30:34+00:00Added an answer on May 30, 2026 at 7:30 am

    Firstly, don’t parse ls output programmatically. It’s nearly guaranteed to break at some point, and to do so in some spectacular fashion. Parsing the output of find is only marginally safer (directory names on most Unixes can contain newline characters, for example; I don’t see your code dealing well with that possibility).

    Perl has a stat function which will give you the date and time of any file or directory (atime, mtime, or ctime, as available), as well as a bunch of other information. You can then use something like strftime to format these timestamps for nicer output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello all i have one json object like {event1:{title:My birthday,start:12\/27\/2011 10:20 ,end:12\/27\/2011 00:00 },event2:{title:My
Hello I have a table on which I have denied SELECT privs to a
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
Hello! I would like to extract all citations from a text. Additionally, the name
Hello I have been having trouble with this for a while now. I have
hello friends i am trying to get a list of user id and want
Hello ever one I want to ask a question about file opening.I want to
Hello i have a TextField on my scene. It haves only digits, user input
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.